diff --git a/docs/output.json b/docs/output.json index 2d318859b9..f9fd4e2b57 100644 --- a/docs/output.json +++ b/docs/output.json @@ -264,6 +264,26 @@ "isStatic": false, "shortDescription": "", "description": "" + }, + { + "examples": [], + "params": [ + { + "name": "module", + "type": "string", + "required": null, + "shortDescription": "", + "description": "" + } + ], + "platform": null, + "name": "validateToken", + "type": [ + "any" + ], + "isStatic": false, + "shortDescription": "", + "description": "" } ], "name": "NbEmailPassAuthProvider", diff --git a/src/framework/auth/providers/email-pass-auth.provider.ts b/src/framework/auth/providers/email-pass-auth.provider.ts index 0ade040a4a..27f217c3ef 100644 --- a/src/framework/auth/providers/email-pass-auth.provider.ts +++ b/src/framework/auth/providers/email-pass-auth.provider.ts @@ -205,6 +205,7 @@ export class NbEmailPassAuthProvider extends NbAbstractAuthProvider { return res; }), + this.validateToken('login'), map((res) => { return new NbAuthResult( true, @@ -245,6 +246,7 @@ export class NbEmailPassAuthProvider extends NbAbstractAuthProvider { return res; }), + this.validateToken('register'), map((res) => { return new NbAuthResult( true, @@ -401,6 +403,21 @@ export class NbEmailPassAuthProvider extends NbAbstractAuthProvider { ); } + protected validateToken (module: string): any { + return map((res) => { + const token = this.getConfigValue('token.getter')(module, res); + if (!token) { + const key = this.getConfigValue('token.key'); + console.warn(`NbEmailPassAuthProvider: + Token is not provided under '${key}' key + with getter '${this.getConfigValue('token.getter')}', check your auth configuration.`); + + throw new Error('Could not extract token from the response.'); + } + return res; + }); + } + protected getActionEndpoint(action: string): string { const actionEndpoint: string = this.getConfigValue(`${action}.endpoint`); const baseEndpoint: string = this.getConfigValue('baseEndpoint');