migrate firebase auth

This commit is contained in:
2026-03-09 18:57:09 +01:00
parent f7be5c082a
commit a569c070c5
5 changed files with 38 additions and 24 deletions

View File

@@ -0,0 +1,22 @@
import {Injectable} from '@angular/core';
import {CanActivate, Router, UrlTree} from '@angular/router';
import {Auth, authState} from '@angular/fire/auth';
import {Observable} from 'rxjs';
import {map, take} from 'rxjs/operators';
@Injectable({
providedIn: 'root',
})
export class AuthGuard implements CanActivate {
public constructor(
private auth: Auth,
private router: Router
) {}
public canActivate(): Observable<boolean | UrlTree> {
return authState(this.auth).pipe(
take(1),
map(user => (user ? true : this.router.createUrlTree(['user', 'login'])))
);
}
}