so I know with Firebase auth they have the createUserWithEmailAndPassword() function. But I was wondering, how can I copy the UID it sets for that user? Because I need to also save alternate information, so I need to send the UID to my own database as well?
Asked
Active
Viewed 45 times
0
-
There is no way to add your own arbitrary properties to the Firebase Authentication user profile. See https://stackoverflow.com/search?q=%5Bfirebase-authentication%5D%5Bjavascript%5D+store+additional+information – Frank van Puffelen Sep 11 '20 at 14:48
1 Answers
1
According to Firebase documentation, createUserWithEmailAndPassword returns a Promise to a UserCredential object, so you can do this:
async function signUp(email, password, nickname) {
const userCredential = await firebase.auth().createUserWithEmailAndPassword(email, password);
const uid = userCredential.user.uid;
// Now you can use *uid* to store data related to your user.
// For example in firestore:
await firebase.firestore().doc(`/users/${uid}`).set({nickname});
// For example as http data:
await fetch("https://...", method="POST", body: JSON.stringify({uid, nickname});
}

Louis Coulet
- 3,663
- 1
- 21
- 39
-
Ah I see thank you. So if I wasnt using firestore and instead my own DB in place of `await firebase.firstore().doc(`/users/${uid}`).set({nickname, age});` I can put a JSON POST to my PHP to make the user? – Jordz2203 Sep 11 '20 at 12:52
-
Yes indeed, Firestore was just an example. Your use-case is perfectly valid, you can use uid as you want. – Louis Coulet Sep 11 '20 at 13:00