Home > Software design >  Is it possible when registering a user via firebase and react to collect his first name, last name,
Is it possible when registering a user via firebase and react to collect his first name, last name,

Time:12-25

I use the updateProfile function, but it seems to only collect first name and photo ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ

ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ

import firebaseConfig from "../firebaseConfig";
import { getAuth, createUserWithEmailAndPassword, updateProfile, onAuthStateChanged } from "firebase/auth";
import { useNavigate } from "react-router-dom";
const Singup = () => {
  const auth = getAuth();
  const navigate = useNavigate();
  let [name, setName] = useState("");
  let [secondName, setSecondName] = useState("");
  let [phone, setPhone] = useState("");
  let [index, setIndex] = useState("");
  let [email, setEmail] = useState("");
  let [password, setPassword] = useState("");
  let [err, setErr] = useState("");
  let handleSubmit = () => {
    if (!name && !secondName && !phone && !index && !email && !password) {
      setErr("Fill the all details!");
    } else if (!name) {
      setErr("Enter your name!");
    } else if (!secondName) {
      setErr("Enter your second name!");
    } else if (!phone) {
      setErr("Enter your phone!");
    } else if (!index) {
      setErr("Enter your index!");
    } else if (!email) {
      setErr("Enter your email!");
    } else if (!password) {
      setErr("Enter your password!");
    } else if (password.length < 6) {
      setErr("Password need minimum 6 character!");
    } else {
      createUserWithEmailAndPassword(auth, email, password)
        .then((userCredential) => {
          // Signed in
          updateProfile(auth.currentUser, {
            displayName: name,
            displaySecondName: secondName,
            displayPhone: phone,
            displayIndex: index,
          }).then(() => {
            // Profile updated!
            setErr("");
            navigate("/");
          });
        })
        .catch((error) => {
          console.log(error.code);
          if (error.code == "auth/email-already-in-use") {
            setErr("Email already in use!");
          } else {
            setErr("");
          }
        });
    }
  };
  onAuthStateChanged(auth, (user) => {
    if (user) {
      navigate("/");
    }
  })

ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ ᅠ

CodePudding user response:

You must have a user schema defined and exported as a model somewhere in your project directory. Make sure that it contains all the required fields. Then, in your updateProfile function, you can access and change any property that you want.

Also, provide the code for your function as it helps in understanding the question better.

  • Related