Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

114
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda