thereef/src/app/core/guards/auth.guard.ts
import { inject } from '@angular/core';import { CanActivateFn, Router } from '@angular/router';import { AuthService } from '../../../services/auth.service';import { map } from 'rxjs'; export const authGuard: CanActivateFn = (route, state) => { const authService = inject(AuthService); const router = inject(Router); return authService.isLoggedIn().pipe( map(isLoggedIn => { if (isLoggedIn) { return true; } else { authService.clearSession(); router.navigate(['/login']); return false; } }) )};