mirror of
https://github.com/andwati/zitadel.git
synced 2026-10-26 09:12:16 +00:00
25 lines
811 B
TypeScript
25 lines
811 B
TypeScript
import { Injectable } from '@angular/core';
|
|
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
|
|
import { Observable } from 'rxjs';
|
|
|
|
import { AuthenticationService } from '../services/authentication.service';
|
|
import { GrpcAuthService } from '../services/grpc-auth.service';
|
|
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class AuthGuard implements CanActivate {
|
|
constructor(private auth: AuthenticationService, private authService: GrpcAuthService) { }
|
|
|
|
public canActivate(
|
|
_: ActivatedRouteSnapshot,
|
|
state: RouterStateSnapshot,
|
|
): Observable<boolean> | Promise<boolean> | Promise<any> | boolean {
|
|
if (!this.auth.authenticated) {
|
|
return this.auth.authenticate();
|
|
}
|
|
return this.auth.authenticated;
|
|
}
|
|
}
|