0

I have a strict requirement to only allow a logged in user to open my web app in one tab. I've noticed that WhatsApp and Google Messenger's web apps have implemented this. For example, trying to open those apps in more than one tab (be it on the same browser, different browser, or even different device) results in these warnings:

enter image description here

enter image description here

Anyone know how this is done? There must be some sort of sync happening between the server and the client to ensure that only one tab is open. But this would require a unique tab identifier, which can get quite complicated to build reliably. Anyone know how WhatsApp and Google Messenger are doing it? Their technique seems to work flawlessly.

Johnny Oshika
  • 50,113
  • 37
  • 162
  • 257

1 Answers1

1

I don't know exactly how this is done at WhatsApp and Google Messenger, but if you work with WebSockets (your post hast the tag "websocket", so I assume, you do) every tab has its single connection to the server, and if your users need to be logged in you could check if the user has already a open weboscket connection to your server.

Apollo79
  • 516
  • 1
  • 11
  • Very interesting approach. I don't actually use websockets at the moment, but it is something I can introduce. I currently use gRPC via Firebase's Firestore, so that's another area I can pursue. Thanks for the suggestion. – Johnny Oshika Feb 10 '22 at 18:35
  • I have no experiences with Firebase and its Firestore nor gRPC, but maybe this approach helps you to implement something similar. Maybe JSON WebTokens are something other you could work with. – Apollo79 Feb 10 '22 at 18:43