Oidc-client-js: 'getUser()' not returning the user in the new browser tab

Created on 16 Mar 2017  路  6Comments  路  Source: IdentityModel/oidc-client-js

I am using oidc-client in my Angular 2 and have this code on my login page to get the user if user is logged in:

getUser() {
    this.userManager.getUser().then((user: User) => {
      if (user) {
        this.user = user;
      }
    });
  }

which is working fine after I login.

But after user being logged in if I open my login url in second separate tab this.userManager.getUser() can't find the user, it is just returning null. At the same time If I just refresh the original login page in the first browser tab this.userManager.getUser() it is still works returning the user.

So any new tab I am opening this.userManager.getUser() do not getting the user but still works on the first original tab if I am refreshing that.

question

Most helpful comment

@kuncevic Did you check what storage oidc client is using ? I think it uses session storage by default.

All 6 comments

@kuncevic Did you check what storage oidc client is using ? I think it uses session storage by default.

@kuncevic Did you check what storage oidc client is using ? I think it uses session storage by default.

What s/he said. You can implement or change the user store being used to work for your requirements.

@kuncevic did you find the solution to this ?

How is it that a question was answered with another question and then closed?
I'm relatively new to this and I don't know how to place a question but I can see that the user @kuncevic opened it as an issue and @brockallen added the label question. Anyways, user @raasmasood and I myself also have this problem.

I am using oidc-client latest (1.7). I don't really know when it started to happen but some time ago my app could be opened in several tabs and now opening an item detail in another tab says UserManager.getUser: user not found in storage in the console.

I am very sorry if this is not the way of placing my comment on a closed issue but this was the only one I could find highly matching my specific problem. I apologize beforehand.

The answer is that by default sessionStorage is used to maintain the session. sessionStorage is per-window, thus it's expected behavior that a new tab will not have a session. If you don't like that behavior, as I mentioned, you can change it by changing which storage is used - it's on the options class.

Thanks, I just did it and it worked. I never had to do that for it to work but now i have! :D all cool. Thanks a lot again.

Was this page helpful?
0 / 5 - 0 ratings