Adding login and giuard
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
95ee995051
commit
e2cd09bb99
@ -1,6 +1,5 @@
|
||||
import { Routes } from '@angular/router';
|
||||
import {LoginComponent} from "./component/login/login.component";
|
||||
import {AuthGuard} from "./guard.guard";
|
||||
|
||||
export const routes: Routes = [
|
||||
{path: 'login',component:LoginComponent}
|
||||
];
|
||||
|
@ -1,5 +1,6 @@
|
||||
import {Link} from "../model/link.model";
|
||||
|
||||
export var LINKS :Link[] = [
|
||||
{$name:"/Accueil",$link:""}
|
||||
{$name:"Accueil",$link:""},
|
||||
{$name:"Ingredients",$link:"/ingredients"}
|
||||
]
|
||||
|
@ -0,0 +1,17 @@
|
||||
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;
|
||||
};
|
@ -0,0 +1,17 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { CanActivateFn } from '@angular/router';
|
||||
|
||||
import { AuthGuard } from '../../app/guard.guard';
|
||||
|
||||
describe('guardGuard', () => {
|
||||
const executeGuard: CanActivateFn = (...guardParameters) =>
|
||||
TestBed.runInInjectionContext(() => AuthGuard(...guardParameters));
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(executeGuard).toBeTruthy();
|
||||
});
|
||||
});
|
Loading…
Reference in new issue