added better auth guard to admin page

This commit is contained in:
itzMiney committed 2026-03-20 17:37:05 +01:00
1 parent f7300f3fb9
commit 49ff565fc0
6 files changed
+30 -14

No files matched your search

+6 -6
View File
@@ -46,20 +46,20 @@ export class AuthService {
const token = this.token;
if (!token) {
this.logout();
localStorage.removeItem('token');
return of(false);
}
try {
const payload = JSON.parse(atob(token.split('.')[1]));
const isValid = payload.exp * 1000;
const expiresAt = payload.exp * 1000;
if (!isValid) {
this.logout();
if (!payload.exp || Date.now() >= expiresAt) {
localStorage.removeItem('token');
return of(false);
}
} catch {
this.logout();
localStorage.removeItem('token');
return of(false);
}
@@ -68,7 +68,7 @@ export class AuthService {
}).pipe(
map(() => true),
catchError(() => {
this.logout();
localStorage.removeItem('token');
return of(false);
})
);