0

I am searching for a way to share the same session between the browser tabs without requiring another authentication. There is a way to do that with the combination of session storage and local storage as pointed out here.

The problem here is that whenever you restore the tabs, the session storage will be restored as well for Chrome and Firefox browsers. This is quite a bad practice for my use case.

For example, the browser is shut down for a reason and then another user started to use the same machine. I would not prefer that the other user could access the previous user's session by just restoring the tab.

Could it be possible to solve this issue with cookies maybe ? Any proper solution or a workaround is welcome.

Yagi
  • 27
  • 5
  • 1
    If you only want to persist and show data to a certain user, can you not just authenticate the user? – Alex Feb 03 '21 at 15:25
  • 1
    I couldn't find a better solution. This is the way I will have to follow. Thanks for your help ! – Yagi Feb 11 '21 at 13:45

1 Answers1

2

As Alex is pointing out in his comment, it's best to implement some form of authentication for this use case.

If you expect different users to use one machine and don't want their sessions to overlap, it's pretty much your only solution.

As you said yourself, sessionStorage is limited to a given tab while the next highest option would be localStorage (that one however remains even after closing the browser). Perhaps you could try to listen to a browser close event or remove the localStorage entry after a given time but that too is not even close to being reliable.

As for cookies, you'd be looking at the same situation as with localStorage.

Aldin Bradaric
  • 733
  • 3
  • 10