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.