0

I am implementing a web application that uses firebase and react authentication, I want to restrict login to only one session per user, in such a way that if the same user tries to login to their account on two devices at the same time, just let it login the first, and in the second I get an error message, but I am not clear about what I should do to achieve this, I would greatly appreciate the help provided.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    Does this answer your question? [Limit concurrent logins by an authenciated user in Firebase](https://stackoverflow.com/questions/19754819/limit-concurrent-logins-by-an-authenciated-user-in-firebase) – ElectricShadow Jun 04 '21 at 22:37

1 Answers1

0

If you have users collection where you keep extra information about your users, you could add an extra field there loggedIn and set it to true when the user logs in.

If you don't have this collection, create one specifically for this purpose. Call it something like loggedInUsers and keep uid of logged in users there.

Then after each login, check either loggedIn value on the user or check if uid is present in loggedInUsers, and allow/decline as needed.

Brian
  • 516
  • 3
  • 8
  • Hello, thank you very much for your answer, first I thought about this same solution but in case the user refreshes the page where he is currently being the persistent validation, the access to the user who was already there would be blocked. – Moises Polo Jun 05 '21 at 13:42