From 8ffb3069135db64bd7ffb225d0730fc3aa6f8ae2 Mon Sep 17 00:00:00 2001 From: George Kalampokis Date: Mon, 7 Sep 2020 18:14:54 +0300 Subject: [PATCH] Return null principal if the expiredAt is actually expired --- dmp-frontend/src/app/core/services/auth/auth.service.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dmp-frontend/src/app/core/services/auth/auth.service.ts b/dmp-frontend/src/app/core/services/auth/auth.service.ts index af4604994..d871e6db7 100644 --- a/dmp-frontend/src/app/core/services/auth/auth.service.ts +++ b/dmp-frontend/src/app/core/services/auth/auth.service.ts @@ -49,7 +49,11 @@ export class AuthService extends BaseService { } const principalJson = localStorage.getItem('principal'); if (!principalJson) { return null; } - const principalObj = JSON.parse(principalJson) as Principal; + let principalObj = JSON.parse(principalJson) as Principal; + principalObj.expiresAt = new Date(principalObj.expiresAt); + if (principalObj.expiresAt < new Date()) { + return null; + } return principalObj; } @@ -132,6 +136,8 @@ export class AuthService extends BaseService { return this.http.post(url, null, { headers: headers }).pipe( map((res: any) => { const princ = this.current(res.payload); + princ.expiresAt = new Date(princ.expiresAt); + console.log("Token Expires at: " + princ.expiresAt.toDateString() + ' ' + princ.expiresAt.toLocaleTimeString()); return princ; }), catchError((error: any) => {