0

I am trying to have different tabs of the same domain NOT share the local storage.

The reason is that I would need to allow multiple users to be authenticated on different tabs. Authentication is achieved through a JWT Token stored in local storage.

So far the workarounds I am thinking of are the following:

  • Open a new tab in incognito mode (sadly not technically feasible)
  • Use a library such as across-tabs and through parent child comunication tell the child tab to use session storage rather than local storage

Is there a way to have e.g. a parent tab open a child tab and have him use an "unsychronized" storage? If not, what strategy would you use?

Aaron Ullal
  • 4,855
  • 8
  • 35
  • 63
  • `I would need to allow multiple users to be authenticated on different tabs` why is this a requirement in the first place? Let's make sure this isn't an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem/66378#66378). –  Jul 29 '19 at 08:11
  • @ChrisG I was trying to explain why I am trying to keep different versions of local storage just to give some context :) – Aaron Ullal Jul 29 '19 at 08:16
  • That's not what I asked; why do you need multiple users authenticated in the same browser? –  Jul 29 '19 at 08:19
  • Did you read this thread ? https://stackoverflow.com/questions/4201239/in-html5-is-the-localstorage-object-isolated-per-page-domain . – Prasanna Jul 29 '19 at 08:19
  • @ChrisG sorry but could you help me understand how the reason of multiple user authentication is relevant? I am sure this is not a XY problem, because the multiple user authentication is just an example..it could be anything else. I am simply trying to figure out ways to differentiate local storages between same domain tabs – Aaron Ullal Jul 29 '19 at 08:25
  • @Prasanna thank you for sharing the post. I read it but sadly in the answer it does not mention what strategies are available to differentiate local storage – Aaron Ullal Jul 29 '19 at 08:26
  • Firefox has an [extension](https://addons.mozilla.org/en-US/firefox/addon/multi-account-containers/) that allows separate cookies. Maybe that includes localStorage? Anyway, if you refuse to tell me the actual use-case, how am I supposed to suggest an alternate solution? Which is the reason why I'm asking. –  Jul 29 '19 at 08:35
  • "I am simply trying to figure out ways to differentiate local storages between same domain tabs", you can associate a tab with a unique key in your browser and save it to the local storage. Or can even have your server keep track of your local storage. You send in user details from the browser, the server keeps track of whatever you need. But as @ChrisG has mentioned, without use case the problem is still not clear – Prasanna Jul 29 '19 at 08:40

1 Answers1

1

Maybe you just add some user-related information (like id) into keys in localStorage? That would allow to keep information for multiple users.

Note, that it doesn't make information private, but if you can just switch a tab to get the same information, seems like you don't need it.

Qwertiy
  • 19,681
  • 15
  • 61
  • 128