You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
414 B
18 lines
414 B
import {CanActivateFn, Router} from '@angular/router';
|
|
import {LoginService} from "./service/login.service";
|
|
import {inject} from "@angular/core";
|
|
|
|
|
|
export const AuthGuard: CanActivateFn = (route, state) => {
|
|
const auth = inject(LoginService)
|
|
const router = inject(Router);
|
|
|
|
if(!auth.isLogged()){
|
|
router.navigateByUrl('/login');
|
|
auth.login();
|
|
return false;
|
|
}
|
|
auth.logout();
|
|
return true;
|
|
};
|