From daa51bafb13aa7c4b3366e408e18cbb4fe7782f4 Mon Sep 17 00:00:00 2001 From: Romain Verger Date: Thu, 3 Mar 2022 14:57:55 +0100 Subject: [PATCH] delete token expiration --- src/app/services/auth.guard.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/services/auth.guard.ts b/src/app/services/auth.guard.ts index 7ae6686..f16c965 100644 --- a/src/app/services/auth.guard.ts +++ b/src/app/services/auth.guard.ts @@ -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; }