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

+13
View File
@@ -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']))
);
};