mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-05 20:02:05 +08:00
[express-jwt] Correct error in callback for secret.
Correct error for secret type in long callback. Split the callbacks in two interfaces. Add some test case.
This commit is contained in:
@@ -13,6 +13,25 @@ app.use(jwt({
|
||||
userProperty: 'auth'
|
||||
}));
|
||||
|
||||
app.use(jwt({
|
||||
secret: (req: express.Request,
|
||||
payload: any,
|
||||
done: (err: any, secret: string) => void) => {
|
||||
done(null, 'shhhhhhared-secret');
|
||||
},
|
||||
userProperty: 'auth'
|
||||
}));
|
||||
|
||||
app.use(jwt({
|
||||
secret: (req: express.Request,
|
||||
header: any,
|
||||
payload: any,
|
||||
done: (err: any, secret: string) => void) => {
|
||||
done(null, 'shhhhhhared-secret');
|
||||
},
|
||||
userProperty: 'auth'
|
||||
}));
|
||||
|
||||
var jwtCheck = jwt({
|
||||
secret: 'shhhhhhared-secret'
|
||||
});
|
||||
@@ -28,4 +47,4 @@ app.use(function (err: any, req: express.Request, res: express.Response, next: e
|
||||
} else {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
6
types/express-jwt/index.d.ts
vendored
6
types/express-jwt/index.d.ts
vendored
@@ -12,8 +12,10 @@ export = jwt;
|
||||
declare function jwt(options: jwt.Options): jwt.RequestHandler;
|
||||
declare namespace jwt {
|
||||
export type secretType = string | Buffer
|
||||
export interface SecretCallbackLong {
|
||||
(req: express.Request, header: any, payload: any, done: (err: any, secret?: secretType) => void): void;
|
||||
}
|
||||
export interface SecretCallback {
|
||||
(req: express.Request, header: any, payload: any, done: (err: any, secret?: boolean) => void): void;
|
||||
(req: express.Request, payload: any, done: (err: any, secret?: secretType) => void): void;
|
||||
}
|
||||
|
||||
@@ -25,7 +27,7 @@ declare namespace jwt {
|
||||
(req: express.Request): any;
|
||||
}
|
||||
export interface Options {
|
||||
secret: secretType | SecretCallback;
|
||||
secret: secretType | SecretCallback | SecretCallbackLong;
|
||||
userProperty?: string;
|
||||
skip?: string[];
|
||||
credentialsRequired?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user