Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

updateProfile is not a function (Firebase)

I am learning React but when I register a user(using createUserWithEmailAndPassword) and try to update the displayName property I get the error as "user1.updateProfile is not a function".

How can I solve this error?

My code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const register = async (e) => {
        if (name.length == 0) {
            alert("name cannot be empty");
        } else {
            const userWithEmailAndPassword = await createUserWithEmailAndPassword(auth, email, password)
                .then((auth1) => {
                    const user1 = auth.currentUser;
                    user1.updateProfile({
                        displayName: name
                    });
                })
                .catch(error => alert(error.message))
            console.log(userWithEmailAndPassword);
        }
    }

>Solution :

The updateProfile function needs to be imported from Firebase Auth SDK directly when using the Modular SDK as shown below:

import { createUserWithEmailAndPassword, updateProfile } from "firebase/auth"

const register = async (e) => {
  if (name.length == 0) {
    alert("name cannot be empty");
  } else {
    const { user } = await createUserWithEmailAndPassword(auth, email, password)
    console.log(`User ${user.uid} created`)
    await updateProfile(user, {
      displayName: name
    });
    console.log("User profile updated")
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading