Skip to content

Commit

Permalink
fix: add UrlTree return type to KeycloakAuthGuard
Browse files Browse the repository at this point in the history
  • Loading branch information
luchsamapparat authored and jonkoops committed Dec 3, 2019
1 parent 412d8a0 commit de739a1
Showing 1 changed file with 5 additions and 3 deletions.
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://github.com/mauriciovigolo/keycloak-angular/LICENSE
*/

import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { CanActivate, Router, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree } from '@angular/router';

import { KeycloakService } from './keycloak.service';

Expand Down Expand Up @@ -35,7 +35,7 @@ export abstract class KeycloakAuthGuard implements CanActivate {
* @param route
* @param state
*/
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean> {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<boolean | UrlTree> {
return new Promise(async (resolve, reject) => {
try {
this.authenticated = await this.keycloakAngular.isLoggedIn();
Expand All @@ -53,11 +53,13 @@ export abstract class KeycloakAuthGuard implements CanActivate {
* Create your own customized authorization flow in this method. From here you already known
* if the user is authenticated (this.authenticated) and the user roles (this.roles).
*
* Return a UrlTree if the user should be redirected to another route.
*
* @param route
* @param state
*/
abstract isAccessAllowed(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Promise<boolean>;
): Promise<boolean | UrlTree>;
}

0 comments on commit de739a1

Please sign in to comment.