I'm submitting a ... (check one with "x")
Current behavior:
When using both access and refresh tokens, there is a tactic to refresh the access token, but not to handle when a Refresh tokens expires. My server could send a request with something like {status: 401, message: "Token expired"}
Expected behavior:
N/A
Steps to reproduce:
N/A
Related code:
npm, node, OS, Browser
OS: Windows 10
npm: 6.4.1
Angular, Nebular
Angular: 7.2.2
Nebular: 3.1.0
Hi @jpandaconnor, Nebular auth module handles refresh token expiration as expected. We can't do something when refresh token expired. So, if you're using some AuthGuard which calls NbAuthService, then in case of refresh token expiration NbAuthService will just say that your token invalid and can't be refreshed. In this situation, you'll be able to redirect the user to the login page.
Here is the common implementation of the AuthGuard using NbAuthService:
@Injectable({ providedIn: 'root' })
export class AuthGuard implements CanActivateChild {
constructor(private authService: NbAuthService, private router: Router) {
}
canActivateChild(): Observable<boolean> {
return this.authService.isAuthenticatedOrRefresh()
.pipe(
tap(authenticated => {
if (!authenticated) {
this.router.navigate(['auth/login']);
}
}),
);
}
}
Hi,
Thank you for your solution. This has solved my query. Just thought it would be best to double check before implementing any solution.
Thank you for your help! :)
Most helpful comment
Hi @jpandaconnor, Nebular auth module handles refresh token expiration as expected. We can't do something when refresh token expired. So, if you're using some
AuthGuardwhich callsNbAuthService, then in case of refresh token expirationNbAuthServicewill just say that your token invalid and can't be refreshed. In this situation, you'll be able to redirect the user to the login page.Here is the common implementation of the
AuthGuardusingNbAuthService: