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

174
Visualizações
Running into issue using Google login with Expo Auth Session

I'm getting this error the first time I open the app and I call the sign in function. It works the second time though.

Cannot prompt to authenticate until the request has finished loading.

Here is my code for Google login:

import React, { useEffect, useState, createContext, useContext, useMemo } from "react"
import * as Google from "expo-auth-session/providers/google"
import * as WebBrowser from "expo-web-browser"
import { GoogleAuthProvider, signInWithCredential, auth, onAuthStateChanged, signOut } from "../firebase"

WebBrowser.maybeCompleteAuthSession()

const config = {
  expoClientId: xxxx
  webClientId: xxxx
  iosClientId: xxxx
  androidClientId: xxxx
}

const AuthContext = createContext({});

export const AuthProvider = ({children}) => {
  const [user,setUser] = useState(null)
  const [error,setError] = useState(null)
  const [req, res, login] = Google.useAuthRequest(config)

  const [loading, setLoading] = useState(true)
  useEffect(
    () =>
      onAuthStateChanged(auth, user => {
        setLoading(true)
        if (user) {
          setUser(user)
          setLoading(false)
        } else {
          setUser(null)
        }
        setLoading(false)
      }),
    []
  )
  const signInWithGoogle = () => {
    setLoading(true)
    login({ showInRecents: true })
      .then(async response => {
        if (response && response.type === "success") {
          const { accessToken, idToken } = response.authentication
          const credential = GoogleAuthProvider.credential(idToken, accessToken)
          await signInWithCredential(auth, credential)
          setLoading(false)
        }
      })
      .catch(error => console.error(error))
      .finally(() => setLoading(false))
  }

Not really sure whats going on, but it works on a second click. My firebase isn't connecting by default either. If sign in and then refresh the app, I don't get user information by default.

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