king_k_rab
02/08/2022, 7:46 PM.auth.session() === Session
(not null
), does that trigger .auth.onAuthStateChange()
? Or is that only for login/signup/logout/password recovery, etc etc...Scott P
02/08/2022, 8:53 PMreact-supabase
library (https://react-supabase.vercel.app/documentation/auth/use-auth-state-change), and noticed that it triggered on its own periodically due to the old user access token expiring and a new one being generated.
You can do something like this (react native example which navigates the user based on their access_token):
js
useAuthStateChange(async (event, session) => {
if (!session?.access_token) {
navigation.reset({
routes: [{ name: "my_authed_route" }],
});
return;
}
if (session?.access_token) {
// User has an access token
// Redirect to main screen, etc
return;
}
});
You could also do something like this if you prefer:
js
useAuthStateChange((event, session) => {
if (event === "SIGNED_OUT") {
// Redirect user to login screen
return;
}
});
Scott P
02/08/2022, 8:53 PMking_k_rab
02/08/2022, 8:55 PM