added better auth guard to admin page
This commit is contained in:
1 parent
f7300f3fb9
commit
49ff565fc0
6 files changed
+30
-14
No files matched your search
@@ -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);
|
||||
})
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user