HasRolesDirective is not working after token is refreshed
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:
- Let the token expire.
- Call
keycloak.updateToken()whenKEYCLOAK_EVENT_SIGNALchanges toKeycloakEventType.TokenExpired. - Observe that
KEYCLOAK_EVENT_SIGNALis nowKeycloakEventType.AuthRefreshSuccess - Open a page with
*haHasRolesand 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"
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!
@mauriciovigolo i can confirm this is still not working properly - can we have a look at this please?
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 :)
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?
H' @kevinpereira-wmtrading ! I'm sorry I don't know ! I'm just a random guy 🤣 Only @mauriciovigolo knows 👀