Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
How to create users with Firebase 9 email and password and save that user's additional data in firebase db collection?

I am struggling now with this question for couple of days. Can somebody provide precise solution based on my code. Please do not refer mi on firebase documentation because it is very unclear. I am not familiar with firebase. In my code I know the problem is somewhere in handleReg method. Curentlly, my user is being created. However, no data is writen in my firebase db collection. I need to achieve to have same doc id(uid) for the new users and his aditional data that i want to store in firebase db collection. Please somebody provide precise solution. It is very frustrating that Firebase documentation does not provide a clear explanation on how to do it. Also I check all stack overflow links. They are not offering solution to this question. Pleas Help

import React, {useState} from "react";
import { View, Button } from "react-native";
import { TextInput } from "react-native-paper";
import { doc, setDoc, collection, addDoc } from "firebase/firestore"; 
import { db } from "../firebase/firebase.authentication";
import { auth } from "../firebase/firebase.authentication";
import { createUserWithEmailAndPassword} from "firebase/auth";

export const RegisterScreen = () => {
  const [email, setEmail] = useState("");
   const [password, setpassword] = useState("");

   const HandleReg = () => {
        createUserWithEmailAndPassword(auth, email, password)
        .then(registredUser => {
            const {uid}= registredUser.user.uid
            const SetData = async ()=>{
                await setDoc(doc(db, "user", uid),{
                    name:"test"
                })  
            }              
        })
    
    }
    return (
        <>
        <View>
        <TextInput value={email}
        onChangeText={(text)=> setEmail(text)}
        />
        <TextInput
        value={password}
        onChangeText={(text)=> setpassword(text)}
        />
        
        <Button title="set" onPress={HandleReg}/>
        </View>
</>

    ); 
} 

And My Firebase js :

import {initializeApp} from "firebase/app"
import { getAuth} from "firebase/auth";
import {getFirestore } from "firebase/firestore"; 

const firebaseConfig = {
    apiKey: "xx",
    authDomain: "xx",
    projectId: "xx",
    storageBucket: "xx",
    messagingSenderId: "xx",
    appId: "xx"
  };

  const app = initializeApp(firebaseConfig);
  export const auth = getAuth(app);
  export const db = getFirestore(app);
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

When it the SetData function being called? Try refactoring the function as shown below:

const HandleReg = async () => {
  const { user } = await createUserWithEmailAndPassword(auth, email, password)
  await setDoc(doc(db, "user", user.uid), { name:"test" }) 
  console.log('Document Added') 
}         
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!