Files
zitadel/console/src/app/guards/auth.guard.ts
T
133aec4568 chore(console): angular 16 (#5870)
* ng 16

* material cdk

* module imports, rmn @accounts

* deps

* lint

* buf

---------

Co-authored-by: Elio Bischof <[email protected]>
2023-05-18 19:28:35 +00:00

35 lines
1.1 KiB
TypeScript

import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { AuthConfig } from 'angular-oauth2-oidc';
import { Observable } from 'rxjs';
import { AuthenticationService } from '../services/authentication.service';
@Injectable({
providedIn: 'root',
})
export class AuthGuard {
constructor(private auth: AuthenticationService) {}
public canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot,
): Observable<boolean> | Promise<boolean> | Promise<any> | boolean {
if (!this.auth.authenticated) {
if (route.queryParams && route.queryParams['login_hint']) {
const hint = route.queryParams['login_hint'];
const configWithPrompt: Partial<AuthConfig> = {
customQueryParams: {
login_hint: hint,
},
};
console.log(`authenticate with login_hint: ${hint}`);
this.auth.authenticate(configWithPrompt);
} else {
return this.auth.authenticate();
}
}
return this.auth.authenticated;
}
}