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

112
Views
Firebase sign in with google for web not redirecting

I was working on a react project in which I wanted to implement google sign in so I used firebase and wrote the following code:

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

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

const app = initializeApp(firebaseConfig);

export const auth = getAuth(app);
export default app;

Creating Context to make the function accessible in the whole application:

import React from 'react';
import FirebaseContext from './FirebaseContext';
import { auth } from '../Firebase/firebase';
import { signInWithRedirect,GoogleAuthProvider,createUserWithEmailAndPassword   } from "firebase/auth";

const FirebaseState = (props)=>{

    const reactSignup = (email,password)=>{
        return createUserWithEmailAndPassword(auth,email,password);
    }

    const googleSignin = ()=>{
        const provider = new GoogleAuthProvider();

        return signInWithRedirect(auth,provider);
    }
    return(
        <FirebaseContext.Provider value={{reactSignup,googleSignin}}>{props.children}</FirebaseContext.Provider>
    )
}

export default FirebaseState;

Calling the function on the desired button click

const {googleSignin} = useContext(FirebaseContext);
const handleGoogleSignin = async()=>{
    try{
      console.log("Sign in attempted");
      await googleSignin();
      history.push("/main");
    }catch(err){
      console.log(err);
    }
  }

Now the problem is that whenever I am running application using npm run start and the button is clicked it does not redirect for sign in but when the application is stopped then it is able to redirect but as my application is no more running that is of no use.

30 sec screen recording of the problem

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

0

Do you try to change signInWithRedirect to signInWithPopup ?

So

import React from 'react';
import FirebaseContext from './FirebaseContext';
import { auth } from '../Firebase/firebase';
import { signInWithPopup,GoogleAuthProvider,createUserWithEmailAndPassword   } from "firebase/auth";

const FirebaseState = (props)=>{

    const reactSignup = (email,password)=>{
        return createUserWithEmailAndPassword(auth,email,password);
    }

    const googleSignin = ()=>{
        const provider = new GoogleAuthProvider();

        return signInWithPopup(auth,provider);
    }
    return(
        <FirebaseContext.Provider value={{reactSignup,googleSignin}}>{props.children}</FirebaseContext.Provider>
    )
}

export default FirebaseState;

Alternative Idea

Detact signInWithRedirect from Context and use the funct directly in your component function like this:

import { auth, provider } from '../../config';
import { signInWithPopup } from '@firebase/auth';
import { Button } from '@chakra-ui/button';

export default function Signup() {
  const loginWithGoogle = () => {
    signInWithPopup(auth, provider);
  };

  return (
    <div>
      <Button onClick={loginWithGoogle}>Signin With Google</Button>
    </div>
  );
}

Alternative Idea 2

Go to Firebase Panel > Authentication > Sign-in Method 

Check your domain, if your domain is in the list delete and add again. Else add your domain.

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!