Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

111
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda