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

HasRolesDirective is not working after token is refreshed

Open davidkopriva98-pr opened this issue 9 months ago • 1 comments

Once logged in, the value of KEYCLOAK_EVENT_SIGNAL is KeycloakEventType.Ready, which allows HasRolesDirective to function correctly. However, when the token expires and keycloak.updateToken() is called, the value changes to KeycloakEventType.AuthRefreshSuccess. Since HasRolesDirective expects the value to be only KeycloakEventType.Ready, no logic is executed after a token refresh.

https://github.com/mauriciovigolo/keycloak-angular/blob/b6ba1f7062d5a67266fdd1cddeddad2ed55fa846/projects/keycloak-angular/src/lib/directives/has-roles.directive.ts#L101-L112

Steps to Reproduce:

  1. Let the token expire.
  2. Call keycloak.updateToken() when KEYCLOAK_EVENT_SIGNAL changes to KeycloakEventType.TokenExpired.
  3. Observe that KEYCLOAK_EVENT_SIGNAL is now KeycloakEventType.AuthRefreshSuccess
  4. Open a page with *haHasRoles and see that it's missing

Expected Behaviour:

HasRolesDirective should not be limited to only work when KEYCLOAK_EVENT_SIGNAL is KeycloakEventType.Ready.

Environment: Angular Version: 19.1 "keycloak-angular": "^19.0.2" "keycloak-js": "^24.0.5"

davidkopriva98-pr avatar Mar 10 '25 11:03 davidkopriva98-pr

Hi @mauriciovigolo,

Would it be possible to submit a PR that includes a check for AuthRefreshSuccess?

Or do you believe that keycloakEvent.type should be set to Ready after the token is refreshed?

Thanks for your time!

gdetra avatar Apr 02 '25 17:04 gdetra

@mauriciovigolo i can confirm this is still not working properly - can we have a look at this please?

AldinDuraki avatar Nov 16 '25 20:11 AldinDuraki

Hey ! Didn't saw your issue, but I solved that ! https://github.com/mauriciovigolo/keycloak-angular/pull/671

It's merged, just wait for deploy. There is a "quick and dirty" fix inside the PR also, you'll be able to make it work before it's deployed if needed.

I think you can close this issue :)

Maxouhell avatar Nov 17 '25 15:11 Maxouhell

Hey ! Didn't saw your issue, but I solved that ! #671

It's merged, just wait for deploy. There is a "quick and dirty" fix inside the PR also, you'll be able to make it work before it's deployed if needed.

I think you can close this issue :)

Hi @Maxouhell, great job! do you mind to tell us when it will be released?

kevinpereira-wmtrading avatar Nov 24 '25 19:11 kevinpereira-wmtrading

H' @kevinpereira-wmtrading ! I'm sorry I don't know ! I'm just a random guy 🤣 Only @mauriciovigolo knows 👀

Maxouhell avatar Nov 25 '25 09:11 Maxouhell