mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
Merge pull request #23580 from danielpa9708/master
Separate user definition to allow extending types for passport package
This commit is contained in:
6
types/passport/index.d.ts
vendored
6
types/passport/index.d.ts
vendored
@@ -4,6 +4,7 @@
|
||||
// Eric Naeseth <https://github.com/enaeseth>
|
||||
// Igor Belagorudsky <https://github.com/theigor>
|
||||
// Tomek Łaziuk <https://github.com/tlaziuk>
|
||||
// Daniel Perez Alvarez <https://github.com/danielpa9708>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@@ -11,7 +12,7 @@ declare global {
|
||||
namespace Express {
|
||||
interface Request {
|
||||
authInfo?: any;
|
||||
user?: any;
|
||||
user?: User;
|
||||
|
||||
// These declarations are merged into express's Request type
|
||||
login(user: any, done: (err: any) => void): void;
|
||||
@@ -25,6 +26,9 @@ declare global {
|
||||
isAuthenticated(): boolean;
|
||||
isUnauthenticated(): boolean;
|
||||
}
|
||||
interface User {
|
||||
[_: string]: any;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -137,3 +137,23 @@ passportInstance.use(new TestStrategy());
|
||||
|
||||
const authenticator = new passport.Authenticator();
|
||||
authenticator.use(new TestStrategy());
|
||||
|
||||
declare global {
|
||||
namespace Express {
|
||||
interface User {
|
||||
username: string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
app.use((req: express.Request, res: express.Response, next: (err?: any) => void) => {
|
||||
if (req.user) {
|
||||
if (req.user.username) {
|
||||
req.user.username = "hello user";
|
||||
}
|
||||
if (req.user.id) {
|
||||
req.user.id = "123";
|
||||
}
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user