0

In my app, user should be able to connect with each other. So to identify each other, they should have some human readable property, which they can share easily. I was wondering if there is any way that, I could have a Human readable "username" similar to Uid?

I was initially planning to save an Email-id of the user in the database, but as it can change, this approach is not recommended. Also, this approach will fail if user logs in using their phone number.

So, is there any in-built Firebase mechanism to this? What are the best practices / design patterns here? What is the commonly used approach in Firebase world, when it comes to 'identifying each other' or 'sharing'?

Mangesh
  • 5,491
  • 5
  • 48
  • 71
  • Many apps need such unique user names. This is not built into Firebase Authentication, but you can easily build it on top of that. See https://stackoverflow.com/q/35243492 or many of the similar questions from these results: https://www.google.com/search?q=site:stackoverflow.com+give+firebase+user+a+unique+username. When these answers speak about Realtime Database, you can apply the same logic to Firestore. – Frank van Puffelen May 14 '20 at 13:46

1 Answers1

1

It's similar to my answer here. You need to keep a separate node in firebase realtime database regarding that. So if your user tries to connect with any other user name user123, you will need to find the node user123 in database and read the UID which will be stored inside and then proceed to your further actions.

Alternatively to make it less lengthy, you could use usernames instead of UID, so there is no question of UID in the application but you will need to take care there are no same usernames and could increase complications.

I'll prefer the first method. Do let me know if you need more assitance.

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84