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