keycloak-angular
keycloak-angular copied to clipboard
Cannot read property 'logout' of undefined
Hi,
I use:
- angular: 9.1.11
- keycloak: 12.0.4
- keycloak-angular: 7.3.1
When I use keycloak.logout()
(the function built-in of keycloak-angular). I have found this issue.
And when debug on console, it seems this._instance
is undefined either. I guess it make all the property are undefined.
No solution has been found. Please help
@hangnkm sounds like you haven't called init()
on the KeycloakService
, have you followed the steps in the README? If so, please share your code. I can't comment on issues that I cannot reproduce.
Hi,
Due to the project credential, I only share the project structure as below:
app.module.ts
app.routing.ts
app.init.ts (keycloak init here)
and in 'app.module.ts', I handle all the sites there
sites.module.ts (all the pages and components were performed here)
sites.routing.ts
The login to app seems fine, but when redirect to sites area, all the functions seem undefined.
Do I need to add the sites.init.ts
into sites package.
Sounds to me like you have multiple KeycloakAngular' modules defined, meaning you have a different
KeycloakService` injected in different modules. That could mean some of them are initialized, some are not. Make sure you have only one in your root module, so the injector will always get it from there.
For more information read the Dependency Injection guide and related articles at the the bottom of the page.