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

189
Views
How to create user collection in firestore after sign in with google?

i am trying to create a user collection in firebase firestore after when user sign in with google. i use these lines of code

const signInWithGoogle = async () => {
    const provider = new fb.auth.GoogleAuthProvider();
    fb.auth().useDeviceLanguage();
    try {
      await fb.auth().signInWithRedirect(provider)
      fb.auth().getRedirectResult().then(function(result) {
        console.log("user sign in", result)
        DB.collection("users").add({
          username: result.additionalUserInfo.profile.given_name,
          name : result.user.displayName,
          photo: result.user.photoURL,
          email: result.user.email,
          uid: result.user.uid,
        });
      }).catch(function (error) {
      console.log("error", error.message)
    });
    } catch (error) {
      console.log(error.message);
    }
  };

but when i click on sign in button, user get sign in but after the signin this code could run

.then(function(result) {
        console.log("user sign in", result)
        DB.collection("users").add({
          username: result.additionalUserInfo.profile.given_name,
          name : result.user.displayName,
          photo: result.user.photoURL,
          email: result.user.email,
          uid: result.user.uid,
        });
      }).catch(function (error) {
      console.log("error", error.message)
    })

but that code , did not called after user sign in. neither console.log("user sign in",result) msg show in console section

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

so this is the previous code , i had used

const signInWithGoogle = async () => {
    const provider = new fb.auth.GoogleAuthProvider();
    fb.auth().useDeviceLanguage();
    try {
      await fb.auth().signInWithRedirect(provider)
      fb.auth().getRedirectResult().then(function(result) {
        console.log("user sign in", result)
        DB.collection("users").add({
          username: result.additionalUserInfo.profile.given_name,
          name : result.user.displayName,
          photo: result.user.photoURL,
          email: result.user.email,
          uid: result.user.uid,
        });
      }).catch(function (error) {
      console.log("error", error.message)
    });
    } catch (error) {
      console.log(error.message);
    }
  };

But the problem was that the second code(getRedirectResult()) was executed while the first code (signInWithRedirect(provider) was running. so its obvious that the second code will give null value in result. because first code is not done.

To solve that problem , i separate these codes in diff files. so in 'signin.js' file i write this code.

const signInWithGoogle = async () => {
    try {
      const provider = new fb.auth.GoogleAuthProvider();
      fb.auth().signInWithRedirect(provider) 
    } catch (error) {
      console.log(error.message);
    }
  }

and the rest of the code is written in the "App.js" file.

fb.auth().getRedirectResult().then(function(result) {
    DB.collection("users").add({
      username: result.additionalUserInfo.profile.given_name,
      name : result.user.displayName,
      photo: result.user.photoURL,
      email: result.user.email,
      uid: result.user.uid,
  });
}); 

And doing that solves the problem.

i recorded a youtube video also for this solution . you can watch here https://youtu.be/EKHk8tpd7dI

about 4 years ago · Juan Pablo Isaza 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!