0

How to prevent multiple login with same credentials from different device in angular Firebase application ?

2 Answers 2

1

Make an UUID and register it in the db on every login. Then check if it match, if it not match, then logout. Can do something like:

import { v4 as uuid } from 'uuid';
// on login
this.uuidValue = uuid();
//Add to db I would say realtime not firestore
this.doCheck();
//Check like
private doCheck() {
  this.checkSub = this.db.object(`uuid/$ID`).valueChanges().subscribe((_uuid: any) => {
  if(this.uuidValue !== _uuid) {
    //logout
    this.checkSub.unsubscribe();
Sign up to request clarification or add additional context in comments.

Comments

0

I can think of two options. A simple not so secure one, and a more complicated more secure one:

  1. You could create a folder in your database that keeps track of logged in users. Then you can query it before or after someone tries to login and handle the event accordingly. Of course this way you can't prevent users from tampering with the javascript.

  2. If you want to make sure that people cannot circumvent your blocker you could implement custom authentication during which you check the database on the server and only return a token if nobody else is logged in. https://firebase.google.com/docs/auth/web/custom-auth

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.