add initial Angular components, services, and routing setup
This commit is contained in:
13
client/src/app/guards/guest-only/guest-only.guard.ts
Normal file
13
client/src/app/guards/guest-only/guest-only.guard.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { inject } from '@angular/core';
|
||||
import { Router, UrlTree, CanActivateFn, CanMatchFn } from '@angular/router';
|
||||
import { AuthService } from '../../services/auth/auth.service';
|
||||
|
||||
function redirectIfLoggedIn(): boolean | UrlTree {
|
||||
const authService = inject(AuthService);
|
||||
const router = inject(Router);
|
||||
// Si déjà connecté -> redirige vers /home
|
||||
return authService.isLoggedIn() ? router.parseUrl('/home') : true;
|
||||
}
|
||||
|
||||
export const guestOnlyCanMatch: CanMatchFn = () => redirectIfLoggedIn();
|
||||
export const guestOnlyCanActivate: CanActivateFn = () => redirectIfLoggedIn();
|
||||
Reference in New Issue
Block a user