Okta Angular 6 Service

I’m using this article to build an Angular app:

I have a navigation menu using routing and I need one on the routed components to have access to the logged in users info (email, name, etc). I tried making a service, but no luck.

I’ve put the same code that is in my app.component.ts in my desired component:

  showLogin() {
this.oktaSignIn.renderEl({el: '#okta-login-container'}, (response) => {
  if (response.status === 'SUCCESS') {
    this.user = response.claims.email;
    this.oktaSignIn.remove();
    this.changeDetectorRef.detectChanges();
  }
});

}

but user is always undefined. Any ideas?

After playing around with it, I got it. Adding this to my ngOnIt helped:

this.oktaSignIn.session.get((response) => {
  console.log(response.login);
  
  if (response.status !== 'INACTIVE') {
    this.user = response.login;
    this.changeDetectorRef.detectChanges();
  } else {
    this.showLogin();
  }
});

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.