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

master
parent 15e2ebd5f8
commit ce2615ca35

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

Loading…
Cancel
Save