I’m currently building a react-native app with expo making use of supabase. However my calls to supabase sometimes just hang and cause my app not to load. I have a userContext
that I wrap my main _Layout.tsx
with and I have the following code in a useEffect in the context:
const [session, setSession] = useState<Session | null>(null)
const [user, setUser] = useState(null)
const [isLoaded, setIsLoaded] = useState(false)
useEffect(() => {
console.log("USEEFFECT")
try {
const getSession = async () => {
console.log("Calling getSession")
const { data, data: { session }, error } = await supabase.auth.getSession()
console.log({ data })
if (error) {
console.error("session error", error)
}
if (!session) {
console.error("no session")
}
if (session) {
setSession(session)
if (session?.user) {
setUser(session.user)
}
}
console.log("setting isLoaded")
setIsLoaded(true)
}
(async () => {
await getSession()
})()
supabase.auth.onAuthStateChange(async (_event, session) => {
console.log("auth change");
setSession(session)
if (!session) {
setUser(null)
} else {
setUser(session.user)
}
setIsLoaded(true)
console.log("setting isLoaded")
})
} catch (err) {
console.error("error loading")
console.error(err)
}
}, [])
My “USEEFFECT” console.log runs as does “Calling getSession”, but it randomly just hangs and never errors or resolves and never logs “data” or any of the error messages so I never see my “setting isLoaded”.
It happens intermittently, but it seems to happy enough that I can only assume it’s a bug with my code rather than an issue with supabase.
I am only on the free tier, but even then I’d expect to see an error around exceeding limits rather than hanging.
Has anyone experienced anything like this before? Or can you see anything obvious?
thnks