I can't get past this error
TypeError: createdUser.updateProfile is not a function at _callee2$ (authActions.jsx:22)
while setting up my Registration form through Firebase.
When I delete the commented "Update the auth profile" section of the code, the registration form goes through, but my document is undefined in Firebase Database section.
export const registerUser = (user) =>
async (dispatch, getState, {getFirebase, getFirestore}) => {
const firebase = getFirebase();
const firestore = getFirestore();
try {
// create the user in firebase auth
let createdUser = await
firebase.auth().createUserWithEmailAndPassword(user.email, user.password);
//update the auth profile
await createdUser.updateProfile({
displayName: user.displayName
})
// create a new profile in firestore
let newUser = {
displayName: user.displayName,
createdAt: firestore.FieldValue.serverTimestamp()
}
await firestore.set(`users/${createdUser.uid}`, {...newUser})
dispatch(closeModal());
} catch (error) {
console.log(error)
throw new SubmissionError({
_error: error.message
})
}
}
createUserWithEmailAndPassword
returns a promise that resolves with a UserCredential
.
You need to change to the following:
let userCredential = await
firebase.auth().createUserWithEmailAndPassword(user.email, user.password);
//update the auth profile
await userCredential.user.updateProfile(...);