const handleSignup = ()=>{
auth()
.createUserWithEmailAndPassword(email, password)
.then((cred) => {
console.log(cred);
firestore()
.collection('users')
.doc(cred.uid)
.set({
display_name:username
})
.then(() => {
console.log('User added!');
});
})
.catch(error => {
console.log(error.code);
if (error.code === 'auth/user-not-found') {
console.error('Invalid Email or password');
}else
console.error('Sorry an error occured');
});
};
I am using the above code to store user details in firestore and I want the document to be same as the credentials uid which is generated after authnetication.But the id in the doc is completely different that the cred.uid.How to fix this?
The correct syntax is cred.user.uid (instead of cred.uid). For source and more information about this topic check firebase password auth docs.
PS: This was already answered in the comments but I posted the response here as well to be easier to spot (as well as suggest that the question has an answer. Thank you @Frank van Puffelen for the suggestion).