Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 813
Rahul Iyer Avatar asked Jul 14 '17 10:07

Rahul Iyer


People also ask

What is FirebaseUser?

Represents a user's profile information in your Firebase project's user database. It also contains helper methods to change or retrieve profile information, as well as to manage that user's authentication state.

How do you uniquely identify a user in firebase?

actually you are on the right way, for unique id you can use user. getUid() this id will always unique for every user as per their register credentials. Token is basically depends on device which will help you into send notification feature.

What is FirebaseAuth?

FirebaseAuth is the gateway to the Firebase authentication API. With it, you can reference Firebase. Auth. FirebaseAuth objects to manage user accounts and credentials. Each Firebase.


2 Answers

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.

like image 90
Frank van Puffelen Avatar answered Oct 19 '22 16:10

Frank van Puffelen


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).

like image 36
Shivam Sharma Avatar answered Oct 19 '22 18:10

Shivam Sharma