🔒Improved token management: delete ENTIRE local user data when the token expires.

master
Alix JEUDI--LEMOINE 3 days ago
parent 15e2ebd5f8
commit ce2615ca35

@ -61,18 +61,25 @@ export class CookiesService {
getToken(): string | null { getToken(): string | null {
const token = this.cookieService.get(this.AUTH_TOKEN_KEY); const token = this.cookieService.get(this.AUTH_TOKEN_KEY);
if (token) { if (token) {
const payload = JSON.parse(atob(token.split('.')[1])); const payload = JSON.parse(atob(token.split('.')[1]));
const expirationDate = new Date(payload.exp * 1000); const expirationDate = new Date(payload.exp * 1000);
if (expirationDate < new Date()) { if (expirationDate < new Date()) {
this.removeToken(); this.removeToken();
this.removeIsAdmin();
this.removeUsername();
this.removeUserId();
this.router.navigate(['/']).then(() => { this.router.navigate(['/']).then(() => {
this.modalService.openModal('login-modal'); this.modalService.openModal('login-modal');
}); });
return null; return null;
} }
} }
return token || null;
return token;
} }
removeToken(): void { removeToken(): void {

Loading…
Cancel
Save