16 lines
390 B
TypeScript
16 lines
390 B
TypeScript
|
|
import { inject } from '@angular/core';
|
||
|
|
import { Router, CanActivateFn } from '@angular/router';
|
||
|
|
import { AuthService } from '../services/auth.service';
|
||
|
|
|
||
|
|
export const authGuard: CanActivateFn = () => {
|
||
|
|
const authService = inject(AuthService);
|
||
|
|
const router = inject(Router);
|
||
|
|
|
||
|
|
if (authService.isAuthenticated()) {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
router.navigate(['/login']);
|
||
|
|
return false;
|
||
|
|
};
|