Return null principal if the expiredAt is actually expired

This commit is contained in:
George Kalampokis 2020-09-07 18:14:54 +03:00
parent b3bf7ab73d
commit 8ffb306913
1 changed files with 7 additions and 1 deletions

View File

@ -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) => {