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

Cannot read property 'logout' of undefined

Open ghost opened this issue 3 years ago • 3 comments

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

ghost avatar Mar 18 '21 09:03 ghost

@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.

jonkoops avatar Mar 18 '21 14:03 jonkoops

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.

ghost avatar Mar 19 '21 01:03 ghost

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.

jonkoops avatar Mar 19 '21 11:03 jonkoops