delete token expiration

This commit is contained in:
Romain Verger 2022-03-03 14:57:55 +01:00
parent 1607634d17
commit daa51bafb1

View File

@ -3,13 +3,15 @@ import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTr
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
import jwt_decode from 'jwt-decode';
import { ApiBackService } from './api-back.service';
import { TokenService } from './token.service';
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
private tokenKey: string;
constructor(private router: Router){
constructor(private router: Router, private tokenService : TokenService){
this.tokenKey = environment.tokenKey;
}
@ -29,6 +31,7 @@ export class AuthGuard implements CanActivate {
const dateExp = new Date(decodedToken.exp * 1000);
if(new Date() >= dateExp) {
// le token a expiré, je n'autorise pas l'accès
this.tokenService.destroyToken();
this.router.navigate(['signin']);
return false;
}