Okta Angular 6 Service

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

https://developer.okta.com/blog/2017/03/27/angular-okta-sign-in-widget

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();
  }
});