Navigating in Guard in Angular5
Tech-Today

Navigating in Guard in Angular5



There are some cases when we need to navigate in a Guard rather than in component. Why? Well, obviously you didn't have to define a component where you need to navigate. An example use case would be a route where you need to navigate given a certain role.

A sample route:
{
path: 'bride',
canLoad: [AuthGuard],
loadChildren: 'app/module/bride/bride.module#BrideModule'
}
A matching guard that navigates defending on role:
@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;
}
}




- React Todo With Middleware
This blog post explains the updates done to React Todo app such as adding Middlewares, Enhancers, API calls, etc. Things to notice: Naming convention, inspired from angular I suffixed the files with .x.js depending on the type. For example .container.js.I...

- Secure Angular4 With Keycloak Role Or Group
Demo template is available for sale for $50. You can send payment via skype at: [email protected] This article will be an extension of an existing one: http://czetsuya-tech.blogspot.com/2017/10/how-to-secure-angular-app-using.html. Normally in the...

- Secure Angular4 App With Keycloak
Demo template is available for sale for $50. You can send payment via skype at: [email protected] Disclaimer: This is not a tutorial on how to setup an Angular^4 project, nor are we going to discuss how to setup a Keycloak server. Needless to say, you...

- How To Signin To Keycloak Using Google
There are 3 set of steps that we must follow in order to come up with a web project that will allow us to login using google's identity provider. Set 1 - Create a google applicationCreate a google application at https://console.developers.google.com...

- How To Remove Kbdrv16.com, Lsass.exe, Usb-hi.exe
Just last night I copied a file from a USB of my apartment mate and I noticed that there was something wrong the way the explorer is showing. I inspect my system and found two instances of services.msc in windows task manager [press ctrl + shift + esc]...



Tech-Today








.