FattyDev1
FattyDev1

Reputation: 106

Auth.currentUser alternative firebase

When I use firebase's

auth.currentUser

for my website, it gets the latest user that logged in, even if multiple users are logged in at the same time. How do I get the info of each user that is logged into their own computer? I am trying to get each user's unique info when they load into a page, but auth.currentUser has only one user logged in at a time?

Here is how I log users in

  auth.signInWithEmailAndPassword(email, password)
    .then((userCredential) => {
      res.redirect(state)
      console.log(`logged in`)
    })
    .catch((error) => {
      var errorMessage = error.message;
      return res.render('login', { error: errorMessage, state: '/' })

    });

Upvotes: 1

Views: 201

Answers (1)

kingkong.js
kingkong.js

Reputation: 753

auth.currentUser is what you seek. Ideally there should not be multiple logged in at the same time in the same browser. auth.currentUser will give you different information depening on who is logged in.

If userA logs in, auth.currentUser will contain information about userA.

If userB logs in, auth.currentUser will contain information about userB

and so on...

auth.currentUser is just a local variable in each user's session

Upvotes: 2

Related Questions