Files
gameovergne-app/client/src/app/guards/guest-only/guest-only.guard.ts
2025-09-24 11:31:28 +02:00

14 lines
582 B
TypeScript

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();