nebular
nebular copied to clipboard
Token is empty or invalid
Issue type
I'm submitting a ... (check one with "x")
- [X] bug report
- [ ] feature request
Issue description
After logging in regularly, I can no longer log in because the response message is token is empty or invalid. it does not happen on all computers or browsers but randomly on different PCs and different operating systems. Yet the authentication response holds the correct token.
This is the angular code I use for authentication
authenticate(data?: any): Observable<NbAuthResult> {
const module = 'login';
const method = this.getOption(`${module}.method`);
const url = this.getActionEndpoint(module);
const requireValidToken = this.getOption(`${module}.requireValidToken`);
return this.http.request(method, url, {body: data, observe: 'response'})
.pipe(
map((res) => {
if (this.getOption(`${module}.alwaysFail`)) {
throw this.createFailResponse(data);
}
return res;
}),
map((res) => {
console.log(res);
return new NbAuthResult(
true,
res,
this.getOption(`${module}.redirect.success`),
[],
this.getOption('messages.getter')(module, res, this.options),
this.createToken(this.getOption('token.getter')(module, res, this.options), requireValidToken));
}),
catchError((res) => {
return this.handleResponseError(res, module);
}),
);
}
instead the json result of request is
{
"headers": {
"normalizedNames": {},
"lazyUpdate": null
},
"status": 200,
"statusText": "OK",
"url": "https://api.XXXXXX.XXX/auth/login",
"ok": true,
"type": 4,
"body": {
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhIGQiLCJyb2xlcyI6WyJhZG1pbiJdLCJleHAiOjE2Mzg0MzkwOTIsImlhdCI6MTYzODQzOTA2MiwidXNlcm5hbWUiOiJhZG1pbiJ9.0AGL6Ztu3hgaAnNdZiMlK9EBGjp4aj8mFtrM7R0TYoM",
"refresh_token": "test"
}
}
json of error:
{
"success": false,
"response": {},
"redirect": null,
"errors": [
"Token is empty or invalid."
],
"messages": [
null
],
"token": null
}
Same behavior, same issue. Do you have any tips/solutions for this?
FYI
"@nebular/auth": "7.0.0",
"@nebular/date-fns": "7.0.0",
"@nebular/eva-icons": "7.0.0",
"@nebular/theme": "7.0.0",
you need configure the token key
https://akveo.github.io/nebular/docs/auth/getting-user-token#use-token
.... NbAuthModule.forRoot({ strategies: [ NbPasswordAuthStrategy.setup({ name: 'email',
token: {
class: NbAuthJWTToken,
key: 'token', // this parameter tells where to look for the token
}
}),
],
forms: {},
}),
...
Of course @dev-alexandre , I have already done this since this behavior is random like @dmaglio
I am having this same issue:
"@nebular/auth": "^9.0.0",
"@nebular/eva-icons": "^9.0.0",
"@nebular/security": "^9.0.0",
"@nebular/theme": "^9.0.0",
I had the same issue, I then realized that my laptop did not have the date and time set automatically and that the date was set to the next day. Fixing the laptop date solved that issue for me... maybe check if that is your problem.