Is it possible for Firestore to generate the same uid when registering a user? - firebase

I have my backend hosted in firebase. Whenever a new user registers I create a new account in my firestore collection. Each user will be identified by a unique uid generated by firebase. Is it possible with enough users to generate the same uid and hence write over another user's data when registering? Or does firestore have any built-in measures to prevent this from happening? Thanks in advance.

Firebase Auth guarantees that each user will have a truly unique ID within your project. There is nothing you have to do. Just accept the UID it generates.

Related

Read Firebase authentication records with R

Using R, I am trying to read the Firebase authentication records created by users for our project, projectID. To be clear, I do not wish to read, nor can I read, the user pswd, just the Firebase authentication ID, known as the User UID.
Firebase creates a unique UID when a user record is created. This in turn populates a collection, call it collectionID, where the key to collectionID is the Firebase authentication User UID. Other information about the user's use of our application is stored within this collection.
I can read the collectionID using the Firestore library created by Luis Rodriguez - github("luizmirodriguez/FireStore") - as follows:
fireStore.download(projectID,collectionID,auth$credentials$access_token).
I cannot download the authentication records shown in Firebase Console with R today. Does anyone know how to do this?
It may be as simple as knowing the name of the collection (authentication, authentication/users, authentication/users_uid all produce errors).
Any help appreciated

is there a way to update firestore document fields based on a firebase Auth user info?

I have successfully added some users' information in firestore documents.
And I have a flutter app where the Client can enter some information after registration, I want to use that information provided to match/link the authenticated user to firestore using a field in the user document, is that possible?
note:
- the data in firestore is created before the user registration. which means the registered user uid is different from the one created in firestore
I would appreciate help in this regard, what is the proper code to do so?
I'm pretty new to this.
user in firestore document id
user uid from firebase
you can create another collection and store other info with the document with documentId as same as uid.so that you can query the collection with the authenticated user with uid.

does signInAnonymously add a record to your Users collection?

I just ran a test of Auth.auth().signInAnonymously and printed the uid of the anonymously created User. I then looked up that ID in my Users collection and didn't find a record. Is that User document only created when you convert them to non-anonymous?
Thanks.
Is that User document only created when you convert them to non-anonymous?
No, the user will appear in the database only when you'll add it. Firebase authentication does not write any data to your Cloud Firestore database.

Firebase auth, is the user uid security sensitive?

I was wondering if getAuth().uid is sensitive/private in anyway? I am planning to use it on a user post something like: post.created_by: getAuth().uid. This makes writing rules/logic a lot easier.
The other way is to use the push id when the user is added to the database, which I'm trying to avoid.
No its safe to use the uid and recommended, firebase uses auth to authenticate the user and the assign the uid to identify the user across firebase.
You will be using uid in your security rules and as well as to identify user info in your db records.
Manually creating another id will render the efficiency of firebase useless.

Cloud Firestore associate logged user with collection

I'd like to know the best approach/pattern to implement for the following use case.
I'm using Firebase Auth to sign up/in users and it's working fine.
As soon as the auth is performed I need to fetch from a Cloud Firestore collection, say user_profile, the data related to the logged user.
The problem is that the collection has its id which is not related to the user, since it's automatically generated by Firestore. So I don't know what to put in <user>
db.collection("user_profile").doc(<user>).get()
A possible solution I came up with is to store the user id inside user_profile and then query the whole collection like this
db.collection("user_profile").where("id", "==", id_from_auth).get()
Making the id field index of the collection.
Is this a good approach?
Is there a better/smarter/automatic way of doing this?
It's customary to store per-user data in a document keyed by the uid of the user authenticated by Firebase Authentication.

Resources