简体   繁体   中英

I can create firebase user using this code, but how can I add display Name, phone Number and other information in default firebase user table? Thanks

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)
            });
    }
}
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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM