I have the following scenario.
A user creates an account on a mobile app and lands in the
/confirm
screen on the mobile app.A user confirms the created account via clicking on the confirmation link in their email on a Computer, taking them to the website and not the mobile app.
The user is being verified successfully by the website via:
const { data, error } = await supabase.auth.verifyOtp({
token_hash: token,
type: "signup",
});
The website tells the user to return to the mobile app.
- On the mobile side (in the
/confirm
screen), I am trying to periodically fetch either session or the user info, but I getnull
for both the session and the user.
useEffect(() => {
const interval = setInterval(async () => {
const { data, error } = await supabase.auth.getSession() // returns null
const {
data: { user },
} = await supabase.auth.getUser() // returns null
if (error) {
captureException(error)
return
}
if (data?.session) {
setAccountConfirmed(true)
clearInterval(interval)
}
}, 3000)
return () => clearInterval(interval)
}, [])
My reasoning is: now that the account has been confirmed on the website, the session should be 'fetchable' in the mobile app as well.
However, that doesn't work.
How can I get the session on the mobile (after the account has been confirmed on the website), so that I can redirect the user to the logged in portion of the mobile app?