25 lines
786 B
TypeScript
25 lines
786 B
TypeScript
import { inject } from '@angular/core';
|
|
import { CanActivateFn, Router } from '@angular/router';
|
|
import { AuthService } from '../services/auth.service';
|
|
import { BootstrapService } from '../services/bootstrap.service';
|
|
import { decideAuthRedirect } from './auth.guard.decision';
|
|
|
|
export { decideAuthRedirect } from './auth.guard.decision';
|
|
export type { AuthGuardInput } from './auth.guard.decision';
|
|
|
|
export const authGuard: CanActivateFn = async () => {
|
|
const auth = inject(AuthService);
|
|
const bootstrap = inject(BootstrapService);
|
|
const router = inject(Router);
|
|
|
|
await bootstrap.ready();
|
|
await auth.waitUntilHydrated();
|
|
|
|
return decideAuthRedirect(
|
|
{
|
|
initialized: bootstrap.initialized(),
|
|
isAuthenticated: auth.isAuthenticated(),
|
|
},
|
|
router,
|
|
);
|
|
}; |