I have created a general function for creating a new user with firebase. It looks like this:
export function createUserEmailPassword(email, password, username) {
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
const user = userCredential.user;
user
.updateProfile({
displayName: username,
})
.then(() => {
alert("Welcome " + user.displayName);
});
})
.catch((error) => {
const errorMessage = error.message;
alert(errorMessage);
});
}
For some reason, user.updatProfile produces the error: "user.updateProfile is not a function", which doesn't let me set the display name.
The goal of the function is to set the displayname to the username upon creating a new user.
The updateProfile() is a top-level function in new Firebase Modular SDK just like createUserWithEmailAndPassword(). Try refactoring the code as shown below:
import { updateProfile } from "firebase/auth"
createUserWithEmailAndPassword(auth, email, password)
.then(async (userCredential) => {
const user = userCredential.user;
await updateProfile(user, {
displayName: username,
})
alert("Welcome " + user.displayName);
})