Is there a way to get the Firebase Auth user ID?

I am looking to get the Auth User (s) ID from Firebase through the NodeJS or Javascript API. I added a screenshot for this so that you have an idea what I'm looking for.

enter image description here

Hope you guys help me with this.

+4
source share
4 answers

Auth data is asynchronous in Firebase 3. Therefore, you need to wait for the event, and then you have access to the current user ID. You cannot get others.

firebase.auth().onAuthStateChanged((user) => {
  if (user) {
    console.log(user.uid);
  }
});

https://firebase.google.com/docs/reference/js/firebase.auth.Auth#onAuthStateChanged

+11
source

Firebase Firebase.getAuth():

var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
var authData = ref.getAuth();

if (authData) {
  console.log("Authenticated user with uid:", authData.uid);
}

:

+1

Firebase API , Auth User (s) UID.
Firebase . ,

"users": {
  "user-1": {
    "uid": "abcd..",
    ....
  },
  "user-2": {
    "uid": "abcd..",
    ....
  },
  "user-3": {
    "uid": "abcd..",
    ....
  }
}

, uid.
, !

0

, .log :

if (firebase.auth().currentUser !== null) 
        console.log("user id: " + firebase.auth().currentUser.uid);
0
source

All Articles