Skip to content

Commit ad8afb0

Browse files
committed
feat(auth): warn about empty token, return falsy result
BREAKING CHANGE: now if login/register returns no value for token, unsuccessful NbAuthResult is returned
1 parent ea0486d commit ad8afb0

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

docs/output.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,26 @@
264264
"isStatic": false,
265265
"shortDescription": "",
266266
"description": ""
267+
},
268+
{
269+
"examples": [],
270+
"params": [
271+
{
272+
"name": "module",
273+
"type": "string",
274+
"required": null,
275+
"shortDescription": "",
276+
"description": ""
277+
}
278+
],
279+
"platform": null,
280+
"name": "validateToken",
281+
"type": [
282+
"any"
283+
],
284+
"isStatic": false,
285+
"shortDescription": "",
286+
"description": ""
267287
}
268288
],
269289
"name": "NbEmailPassAuthProvider",

src/framework/auth/providers/email-pass-auth.provider.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export class NbEmailPassAuthProvider extends NbAbstractAuthProvider {
205205

206206
return res;
207207
}),
208+
this.validateToken('login'),
208209
map((res) => {
209210
return new NbAuthResult(
210211
true,
@@ -245,6 +246,7 @@ export class NbEmailPassAuthProvider extends NbAbstractAuthProvider {
245246

246247
return res;
247248
}),
249+
this.validateToken('register'),
248250
map((res) => {
249251
return new NbAuthResult(
250252
true,
@@ -401,6 +403,21 @@ export class NbEmailPassAuthProvider extends NbAbstractAuthProvider {
401403
);
402404
}
403405

406+
protected validateToken (module: string): any {
407+
return map((res) => {
408+
const token = this.getConfigValue('token.getter')(module, res);
409+
if (!token) {
410+
const key = this.getConfigValue('token.key');
411+
console.warn(`NbEmailPassAuthProvider:
412+
Token is not provided under '${key}' key
413+
with getter '${this.getConfigValue('token.getter')}', check your auth configuration.`);
414+
415+
throw new Error('Could not extract token from the response.');
416+
}
417+
return res;
418+
});
419+
}
420+
404421
protected getActionEndpoint(action: string): string {
405422
const actionEndpoint: string = this.getConfigValue(`${action}.endpoint`);
406423
const baseEndpoint: string = this.getConfigValue('baseEndpoint');

0 commit comments

Comments
 (0)