Jonathan Ma
Jonathan Ma

Reputation: 606

In Firestore, is it okay to set the documentID for a document in a users collection to be the user's uid?

I am creating a database-backed application in native iOS. I see that there is a User UID attribute automatically generated by FirebaseAuth every time a user is created. Is it okay to use this UID as the documentID for a user in a dbUsers table?

My original firebase firestore schema had the UID being a field of the dbUsers collection, but this made it difficult to directly obtain information about the user since I no longer had a pointer (currentUser!.uid) to the user's document in the database and would have to perform a query and iterate over the querySnapshot. I'm wondering if there is a security risk or something else that would make this not a good idea.

List of Firebase UIDs

Upvotes: 1

Views: 36

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317487

Yes, it's OK. In fact, it's very common to do this, as it makes it easy to write per-user security rules for that document.

Upvotes: 2

Related Questions