Rahul Iyer
Rahul Iyer

Reputation: 21005

Is FirebaseUser.getUid() constant for a given user?

I have authenticated my user using phone authentication, and the user object that is returned has this long string when I call user.getUid() :

dn27dhJK..... (some long string).

If I authenticate this user on some other device (using my phone number etc), will user.getUid() always be the same ?

EDIT: From the documentation: https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser

public abstract String getUid ()

Also: Google Play services Returns a string used to uniquely identify your user in your Firebase project's user database. Use it when storing information in Firebase Database or Storage, or even in your own backend.

This identifier is opaque and does not correspond necessarily to the user's email address or any other field.

It is unclear if this id remains constant or not.

Upvotes: 5

Views: 1769

Answers (3)

Frank van Puffelen
Frank van Puffelen

Reputation: 598765

When you first verify the phone number (or first sign in with a social provider, or call createUser), a user account is created - and thus a new unique UID id created. From that moment on, that user/phone number will remain associated with that account/UID. No matter if they re-verify on the same or a different device.

If you delete the account, a new account+UID will be generated when you use that same phone number next time.

Upvotes: 5

Shivam Sharma
Shivam Sharma

Reputation: 1045

If you're using Firebase Authentication in your project:

Remember

  1. Firebase will generate a single unique key(i.e. UID) on registration of a/c whether using Email/Phone number.

  2. This key remain associated to that a/c untill a/c is exist in firebase authentication list.

  3. If your app is uninstalled on phone & then a/c is open in another then we can fetch that key from Firebase cloud auth. service.( UID remain safe).

Upvotes: 1

Ziya ERKOC
Ziya ERKOC

Reputation: 839

This Uid is created when the user signs up and is linked to the phone number that you used. When you sign in you will get the same uid. But if you try to sign up again with the same phone number, it will basically give an error saying this phone number is already signed up.
Hope that explains!

Upvotes: 0

Related Questions