File

app/core/guards/app-authentication-guard.ts

Extends

KeycloakAuthGuard

Index

Methods

Constructor

constructor(router: Router, keycloakAngular: KeycloakService)
Parameters :
Name Type Optional
router Router No
keycloakAngular KeycloakService No

Methods

isAccessAllowed
isAccessAllowed(route: ActivatedRouteSnapshot, state: RouterStateSnapshot)
Parameters :
Name Type Optional
route ActivatedRouteSnapshot No
state RouterStateSnapshot No
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();
			}
		});
	}
}

result-matching ""

    No results matching ""