diff --git a/types/hapi-auth-jwt2/hapi-auth-jwt2-tests.ts b/types/hapi-auth-jwt2/hapi-auth-jwt2-tests.ts index cf51162eb4..50b17e8db6 100644 --- a/types/hapi-auth-jwt2/hapi-auth-jwt2-tests.ts +++ b/types/hapi-auth-jwt2/hapi-auth-jwt2-tests.ts @@ -32,7 +32,7 @@ server.register({ .then(() => { const opts: hapiAuthJwt2.Options = { key: 'NeverShareYourSecret', - async validate(decoded: { id: number }, request) { + async validate(decoded: { id: number }) { return { isValid: !!users[decoded.id], }; @@ -42,5 +42,14 @@ server.register({ issuer: 'test', } }; + const opts2: hapiAuthJwt2.Options = { + key: 'NeverShareYourSecret2', + validate(decoded: { id: number }) { + return { + isValid: !!users[decoded.id], + }; + } + }; server.auth.strategy('jwt', 'jwt', opts); + server.auth.strategy('jwt2', 'jwt', opts2); }); diff --git a/types/hapi-auth-jwt2/index.d.ts b/types/hapi-auth-jwt2/index.d.ts index a93f740bfc..f980cfa6e9 100644 --- a/types/hapi-auth-jwt2/index.d.ts +++ b/types/hapi-auth-jwt2/index.d.ts @@ -39,6 +39,12 @@ declare namespace hapiAuthJwt2 { }; } + interface ValidationResult { + isValid: boolean; + credentials?: any; + response?: ResponseObject; + } + /** * Options passed to `hapi.auth.strategy` when this plugin is used */ @@ -54,11 +60,7 @@ declare namespace hapiAuthJwt2 { * @param decoded the *decoded* and *verified* JWT received from the client in *request.headers.authorization* * @param request the original *request* received from the client */ - validate(decoded: {}, request: Request, tk: ResponseToolkit): Promise<{ - isValid: boolean; - credentials?: any; - response?: ResponseObject - }>; + validate(decoded: {}, request: Request, tk: ResponseToolkit): ValidationResult | Promise; /** * Settings to define how tokens are verified by the jsonwebtoken library