Home > Software design >  Is it safe to use a Firestore auto-generated ID in place of the Firebase user auto-generated ID?
Is it safe to use a Firestore auto-generated ID in place of the Firebase user auto-generated ID?

Time:03-09

The Firebase Authentication auto-generated ID is considerably longer than the Firestore [document] auto-generated ID.

y0b4UcWzyjOvstEdV4aLz6W23oh2 // Firebase Auth
rXGOCJpkccD1WzFdXyA2         // Firestore

I ask because I want to create the user's documents before I create the user itself and so I rely on the Firestore ID for the user's ID and plug that into the create-user function in Auth, which works fine. My question is, is this a good practice? And why is the Auth ID so much longer? Shouldn't document ID's have a bigger key space since documents almost always outnumber users?

CodePudding user response:

Firestore auto-generated document IDs are generated in client-side code, and are therefor statistically generated to be unique.

Firebase Authentication UID are generated by server-side code, which means the server can (and does) check whether they are unique.

Both are going to be unique values though, so using either as a document ID is fine.

  • Related