Home > Blockchain >  I can create firebase user using this code, but how can I add display Name, phone Number and other i
I can create firebase user using this code, but how can I add display Name, phone Number and other i

Time:06-21

This is my funcation code.

const signUpFun = () => {
    if (isValidForm()) {

        createUserWithEmailAndPassword(auth, email, password)
            .then((userCredential) => {
                // Signed in 
                const user = userCredential.user;
                setbitdata({});
            })
            .catch((error) => {
                const errorCode = error.code;
                const errorMessage = error.message;
                setEmailAndPasswordCheck(true)
                setTimeout(() => {
                    setEmailAndPasswordCheck(false)
                }, 3500)
            });
    }
}

CodePudding user response:

import { getAuth, updateProfile } from "firebase/auth";
const auth = getAuth();
updateProfile(auth.currentUser, {
  displayName: "My Name", photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(() => {
  // Profile updated!
}).catch((error) => {
  // An error occurred
});

If you are using firebase version 8, then you should use like these:

import firebase from "firebase";

const user = firebase.auth().currentUser;

user.updateProfile({
  displayName: "My Name",
  photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(() => {
  // Update successful
}).catch((error) => {
  // An error occurred
}); 

Firebase have very great documentation, you should probably read that, as like @Alexandros Giotas mentioned the link for official Documentation for your question

CodePudding user response:

You're probably looking for the updateProfile method.
Using modular imports:

import { getAuth, updateProfile } from "firebase/auth";
const auth = getAuth();
updateProfile(auth.currentUser, {
  displayName: "Your display name here",
  // more updating..
}).then(() => {
  // Success
}).catch((e) => {
  // Handle errors.
});

Remember that updateProfile returns a Promise which you should handle, with either then() & catch() as shown above or await if you're updating within an async function.

I encourage you to read the Firebase docs on updating a user's profile. There are more code snippets there, that answer your question probably better than I did.

  • Related