I am implementing a back end using nestjs, the authentication I am doing with the jwt strategy using passport-jwt. Now I have the question of how to use the refresh token, because once the user accesses with an expired token, I have to ask for another one using the refresh token. How would this be done?
This is my jwt strategy
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy){
constructor(){
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey : fs.readFileSync('./src/auth/publicKey.pem')
}
);
}
async validate(payload: any){
const user = {
userId: payload.sub,
username: payload.preferred_username,
name: payload.name,email:
payload.email,
roles: payload.realm_access.roles};
return user;
}
}