Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firebase pending user id

Firebase has the functionality to create an auth user programmatically which generates 28 char long ID for that user. I have a case where I need to generate the same type of ID without creating a user, sort of pending user ID so that I can create a user later on with the before hand known ID.

What is the best approach to do this?

I can’t seem to find an inbuilt way to generate an auth user ID without creating an auth user (one can do a similar thing for documents by calling doc().id in which case one gets 20 char char-long ID)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I can surely handcraft a function that concats 28 chars using Math.random() and alphabet+numbers, but my concern is that auth user id might be more clever in helping minimize collisions (I’d like to know how it works internally if anyone is familiar with that) and I’d rather reuse what auth is using if possible rather than inventing my own wheel.

Besides, reusing the existing logic would help if anything changes internally in auth, like for example uid lengths will become 50 chars or something.

>Solution :

I have a case where I need to generate the same type of ID without creating a user, sort of pending user ID so that I can create a user later on with the beforehand known ID.

You cannot say, hey Firebase, generate an ID for a user that will be created sometime later. So you cannot generate UIDs in advance. The UID is generated after the user is successfully authenticated in Firebase.

I can’t seem to find an inbuilt way to generate an auth user ID without creating an auth user (one can do a similar thing for documents by calling doc().id in which case one gets 20 char char-long ID)

You cannot find anything related to this because it doesn’t exist.

I can surely handcraft a function that concats of 28 chars using Math.random() and alphabet+numbers, but my concern is that the auth user ID might be more clever to help minimize collisions.

If you need to reserve in advance some IDs that cannot be generated by Firebase in the way you want, then you should consider implementing your own mechanism, but always make sure to have completely unique IDs.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading