Answer the question
In order to leave comments, you need to log in
How and when to refresh a token in Angular 2?
I am using JWT for django. The manual says that there is an option to update the method out of the box.
I pass the token to 127.0.0.1:8000/api-token-refresh/, and I get an error in response:
orig_iat field is required
And when to refresh the token? With each request to the server, make a parallel request to ./api-token-refresh/?
Answer the question
In order to leave comments, you need to log in
Together with the token, the lifetime comes, you bring it to an absolute value, you create a timer subscription, you refresh the token using a refresh token
Alternatively, you can use @auth0/angular-jwt to get the token lifetime :
import {JwtHelperService} from '@auth0/angular-jwt';
export class AuthService {
private jwtHelper: JwtHelperService;
constructor(){
this.jwtHelper = new JwtHelperService();
}
getAccessToken(): string {
return localStorage.getItem('access');
}
getAccessTokenExpirationDate(): Date {
return this.jwtHelper.getTokenExpirationDate(this.getAccessToken());
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question