react-firebase-authentication icon indicating copy to clipboard operation
react-firebase-authentication copied to clipboard

How to access authUser.uid from firebase.js

Open MattHeslington opened this issue 4 years ago • 2 comments

Hello,

Apologies if this is badly worded or an entirely stupid question. I have followed this fantastic tutorial and it's working perfectly. I would now like to allow logged-in users to post content. This is all fine, but I need to name each user's collection something like .collection(${currentUser.uid}). What's the best way to access this value in my component, please? Many thanks for any help. Matt

MattHeslington avatar Jan 06 '21 16:01 MattHeslington

Here's a screenshot of of an Android app using Cloud Firestore showing the user collection with unique id's. As you see user collection document id is unique as in phone number or e-mail! Here's how to Get data with Cloud Firestore

image

erikswed avatar Jan 06 '21 18:01 erikswed

Here's a screenshot of of an Android app using Cloud Firestore showing the user collection with unique id's. As you see user collection document id is unique as in phone number or e-mail! Here's how to Get data with Cloud Firestore

image

Hello Hans, Thank you so much for your reply. I'm sorry I didn't phrase my question correctly. I was wanting to know how, through code, do I access the authUser.uid found in firebase/firebase.js

authUser = { uid: authUser.uid, ... };

I would like to be able to create unique collections in Firestore for each user using their current user id from the Realtime Database. I'm at a loss at the moment. I assume it's either through using the { AuthUserContext } import or the {withFireBase } import but I'm unsure of the actual code. Sincere regards, Matt

MattHeslington avatar Jan 07 '21 02:01 MattHeslington