Reputation: 3043
Using oidc-client-js i have that following:
mgr = new UserManager(settings);
...
this.mgr.events.addUserLoaded(() => {
console.log('UserLoaded hit');
});
this.mgr.events.addUserUnloaded(() => {
console.log('UserUnloaded hit');
});
this.mgr.events.addUserSignedOut(() => {
console.log('UserSignedOut hit');
});
To know that the user is logged in was going to listen to the UserLoaded event but the only event that is getting hit when you log in and out is UserUnloaded.
Upvotes: 0
Views: 2256
Reputation: 21367
try this to check if the user is authenticated, hope it's helpful for you
_user: any;
constructor(){
mgr = new UserManager(settings);
...
mgr.events.addUserLoaded((args) => {
mgr.getUser().then((user) => {
this._user = user;
});
});
}
isLoggedIn(): boolean {
return this._user && this._user.access_token && !this._user.expired;
}
Upvotes: 1
Reputation: 3043
I seems the UserLoaded event only fires when you process the signin callback and not when the user is persisted in session/local storage. I am now using getUser() and check if the user is not null to know that the user is logged in.
Upvotes: 1