I'm running into this problem of redirecting to dashboard page after authenticating. I have backend service that returns the auth token like this.
{
...
session_id: "6NdC3aMn3Smc5fuRCMvJ"
...
}
and my token is set like this
token :{
key : 'session_id',
}
I see auth_app_token getting set in localStorage. But when it tries to redirect I see the error below
"Error: The token 6NdC3aMn3Smc5fuRCMvJ is not valid JWT token and must consist of three parts"
If I change my service response to something like this
data: {
session_id:
}
and configure
token {
key : "data.session_id"
}
I don't see the aut_app_token getting set.
What am I doing wrong here.
Thanks!
So, If I comment out the section of this code, my redirection works just fine. Perhaps, I need to change the getter setting
constructor(private sidebarService: NbSidebarService,
private menuService: NbMenuService,
private userService: UserService,
private analyticsService: AnalyticsService, private authService: NbAuthService) {
this.authService.onTokenChange()
.subscribe((token: NbAuthJWTToken) => {
/*if (token.getValue()) {
this.user = token.getPayload();
}*/
});
}
I think your issue here is that your backend is not using a JWT Token. You can have a look at JWT (JSON Web Token) tokens and what they are at jwt.io. The Nebular auth service and components are ready to work with regular tokens NbAuthSimpleToken or with JWT tokens NbAuthJWTToken.
If your token is not JWT, you need to make sure that you always treat it like a NbAuthSimpleToken. The getPayload() function is specific for the NbAUthJWTToken class, and that's why your app crashes on that point. You can have a look at the regular token class here: https://github.com/akveo/nebular/blob/893d56adfe56a0d4f6e8fe9b9591a20e3bafade4/src/framework/auth/services/token.service.ts#L16
Hope that solved your issue.
Hi @120bits, you just don't need the JWTToken as your token is clearly not JWT.
Skip the step one of the guide (https://akveo.github.io/nebular/#/docs/auth/getting-user-token) and use NbAuthSimpleToken as a type .subscribe((token: NbAuthSimpleToken).
Thanks guys! that helped!
Most helpful comment
I think your issue here is that your backend is not using a JWT Token. You can have a look at JWT (JSON Web Token) tokens and what they are at jwt.io. The Nebular auth service and components are ready to work with regular tokens
NbAuthSimpleTokenor with JWT tokensNbAuthJWTToken.If your token is not JWT, you need to make sure that you always treat it like a NbAuthSimpleToken. The
getPayload()function is specific for theNbAUthJWTTokenclass, and that's why your app crashes on that point. You can have a look at the regular token class here: https://github.com/akveo/nebular/blob/893d56adfe56a0d4f6e8fe9b9591a20e3bafade4/src/framework/auth/services/token.service.ts#L16Hope that solved your issue.