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

202
Views
How to check If registered user when login with google using firebase in react js?

i want to check if the person logged in with Google account, has registered before or not to save to Firestore. Is there any way to check?

 const ggProvider = new GoogleAuthProvider();

 const handleGgLogin = async () => {
    const { user } = await signInWithPopup(auth, ggProvider);

    const collectionRef = collection(db, "Account");
    const payload = {
      displayName: user.displayName,
      email: user.email,
      photoUrl: user.photoURL,
      uid: user.uid,
    };
    await addDoc(collectionRef, payload);
  };
about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

You're looking for the UserInfo.providerId field of the User object.

Something like this:

onAuthStateChanged(auth, (user) => {
  if (user) {
    // User is signed in, see docs for a list of available properties
    // https://firebase.google.com/docs/reference/js/firebase.User
    const uid = user.uid;

    // Show the provider(s) that the user is signed in with
    user.providerData.forEach((userInfo) => { // ๐Ÿ‘ˆ
      console.log(userInfo.providerId);       // ๐Ÿ‘ˆ
    })

    // ...
  }
});

You need the loop, since a user can be signed in with multiple providers at the same time. The provider string for Google is google.com (source).

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!