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
@@ -0,0 +1,13 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { CanActivateFn, Router, UrlTree } from '@angular/router';
|
||||
import { map, Observable } from 'rxjs';
|
||||
import { AuthService } from './shared/services/auth.service';
|
||||
|
||||
export const adminGuard: CanActivateFn = (): Observable<boolean | UrlTree> => {
|
||||
const authService = inject(AuthService);
|
||||
const router = inject(Router);
|
||||
|
||||
return authService.validateToken().pipe(
|
||||
map((isValid) => isValid ? true : router.createUrlTree(['/login']))
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user