Search code examples
firebase-authenticationgoogle-cloud-datastore

Would it be a bad idea to use Firebase UID as the datastore key name for users?


I assume since it's not monotonic, it would create a well distributed key space, and doing so would provide instant lookups. One downside I can think of is locking myself into firebase auth. Is there a better strategy? Often I need to update a user record atomically, especially if it doesn't exist yet, and since transactions only allow ancestor queries (I have not been updated to the new firestore datastore mode as far as I know), I can't very well search and update atomically. Any advice would be greatly appreciated.


Solution

  • It is quite common to use Firebase Authentication's UID as the key for a document for that user, both in Datastore and in Firestore.

    So: no, it won't be a bad idea per se. It of course always depends on your exact use-case and implementation though, so post back with a more concrete question if you run into problems.