SamaSamrin
SamaSamrin

Reputation: 79

Firebase User ID and Current User ID on code do not match

I am new to Firebase and I assumed the user id generated by Firebase Database is the same one I get by using currentUser.getUid(). But as you can see, those two values don't match for my current user.

I can't figure out the reason. Please help. How to solve this? enter image description here

enter image description here

Upvotes: 0

Views: 3826

Answers (2)

Alex Mamo
Alex Mamo

Reputation: 138824

As i can see in your screenshots you are using two different ways for having that unique key, a uid provided by the firebaseUser object and the unique key generated by the push() method. It's obvious that are not the same, becase there are different principles.

The first one is the uid provided by the Firebase authentication and the second by the push() method, that generates a unique id based on the time of the generation.

The best way for using as an identifier for your users is not the uid, nor the pushed id, is the email address, because if a users deletes his account and sign-in again, he'll gets a new uid.

If you want to use the uid, this is the way in which you can retrieve it:

FirebaseUser firebaseUser = firebaseAuth.getCurrentUser();
if (firebaseUser != null) {
    String uid = firebaseUser.getUid();
}

Hope it helps.

Upvotes: 1

Ziya ERKOC
Ziya ERKOC

Reputation: 839

Those are totally different things.
ID that you get with getUid() is an ID that is created when user is signed up to Firebase Authentication. Other one is key created based on the current timestamp in the Firebase Database when you call push() method.
What you could do is instead of creating new person in your database with push method, use the id that you get from getUid()

Upvotes: 1

Related Questions