20230802FertigstellungVonBookMonkey

This commit is contained in:
2023-08-02 11:39:13 +02:00
parent 6ae0d27dd4
commit 02261e7e13
33 changed files with 507 additions and 39 deletions

View File

@@ -0,0 +1,21 @@
import { Inject, inject } from '@angular/core';
import { CanActivateFn, Router } from '@angular/router';
import { AuthService } from './auth.service';
import { map, take } from 'rxjs';
export const authGuard: CanActivateFn = (route, state) => {
const authService = inject(AuthService);
const router = inject(Router);
return authService.isAuthenticated$.pipe(
take(1),
map((isAuthenticated) => {
if (authService.isAuthenticated) {
return true;
} else {
window.alert('Not logged in!');
return router.parseUrl('home');
}
}),
);
};