the-road-to-react-with-firebase / react-firebase-authentication

🔥 Boilerplate Project for Authentication with Firebase in React.
https://www.robinwieruch.de
1.02k stars 298 forks source link

How to access authUser.uid from firebase.js #44

Open MattHeslington opened 3 years ago

MattHeslington commented 3 years ago

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

erikswed commented 3 years ago

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

MattHeslington commented 3 years ago

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