A sample route:
A matching guard that navigates defending on role:
{
path: 'bride',
canLoad: [AuthGuard],
loadChildren: 'app/module/bride/bride.module#BrideModule'
}
@Injectable()
export class AuthGuard implements CanActivate {
constructor( private router: Router, private route: ActivatedRoute ) {
}
canActivate( next: ActivatedRouteSnapshot, state: RouterStateSnapshot ): Observable| Promise | boolean {
console.log( 'registration.guard' )
if ( !KeycloakService.auth.loggedIn || !KeycloakService.auth.authz.authenticated ) {
return false;
}
//check group
if ( KeycloakService.hasGroup( 'Anime' ) ) {
this.router.navigate( ['/bride/postRegistration'] );
} else if ( KeycloakService.hasGroup( 'Vendor' ) ) {
this.router.navigate( ['/bride/postRegistration'] );
}
return true;
}
}
0 nhận xét:
Đăng nhận xét