app/core/guards/app-authentication-guard.ts
KeycloakAuthGuard
Methods |
constructor(router: Router, keycloakAngular: KeycloakService)
|
|||||||||
Parameters :
|
isAccessAllowed | |||||||||
isAccessAllowed(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)
|
|||||||||
Parameters :
Returns :
Promise<boolean>
|
import { Injectable } from '@angular/core';
import {
Router,
ActivatedRouteSnapshot,
RouterStateSnapshot
} from '@angular/router';
import { KeycloakService, KeycloakAuthGuard } from 'keycloak-angular';
@Injectable()
export class AppAuthenticationGuard extends KeycloakAuthGuard {
constructor(
protected router: Router,
protected keycloakAngular: KeycloakService,
) {
super(router, keycloakAngular);
}
isAccessAllowed(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Promise<boolean> {
return new Promise(async (resolve) => {
if (this.authenticated) {
resolve(true);
return;
} else {
this.keycloakAngular.login();
}
});
}
}