keycloak-angular icon indicating copy to clipboard operation
keycloak-angular copied to clipboard

KeycloakAuthGuard example

Open lnksz opened this issue 1 year ago • 4 comments

Bug Report or Feature Request (mark with an x)

- [ ] bug report
- [x] feature request

Versions.

  • keycloak-angular: 15.0.0
  • angular: 17.0.7
  • keycloak: 23.0.4

Desired functionality.

Would be really nice to have the KeycloakAuthGuard being integrated into the example. Not just in the readme.

lnksz avatar Jan 23 '24 10:01 lnksz

Just copy the AuthGuard found on the readme and then use it in the routes (app-routing.module.ts) in the following way

{ path: 'mypath', component: MyComponent , canActivate: [AuthGuard], data: { roles: ['user']}}

Are you experiencing any difficulties?

DeltaFox0018 avatar Jan 27 '24 20:01 DeltaFox0018

See https://github.com/mauriciovigolo/keycloak-angular/issues/526#issuecomment-1914140746 if you want to use Angular v14.2+ functional guards.

ThoSap avatar Jan 30 '24 20:01 ThoSap

Thanks for the replies. I tried out the module with a project with Angular 17 and with standalone modules, and would have found an example for the AuthGuard pretty cool in the example application. As an Angular newbie, I still struggle a bit with a lot of resources using only NgModules, but v17 and the new Angular.dev site convinced me to start a new project with the standalone modules.

I selected "feature request" from the list, because it was the closest to "enhancement/wish".

lnksz avatar Feb 01 '24 10:02 lnksz

me too same issue

Mohamed-Hammada avatar Feb 01 '24 12:02 Mohamed-Hammada