I'm having a little issue with auth and redirects....
# help
b
I'm having a little issue with auth and redirects. All my pages should be gated by login. I've built a
ProtectedRoute
component that checks if there is a user logged in and whether the path is protected, and will
router.push
to /login accordingly. The issue im having is that after
await supabase.signIn()
is called, I’m being redirected to my homepage, but after the redirect
supabase.auth.user()
is still
null
, and my
ProtectedRoute
component is then redirecting back to /login. If I enter the url to go to the home page again, it won’t redirect me and
user
is no longer
null
. In other posts I saw
onAuthStateChange
suggested to be used. But I am already using an AuthProvider similar to the examples that utilise
onAuthStateChange
. I think in my case it may be that the change in path is triggering a redirect before the user state is changed. But I'm not sure how to fix this. I see in a few examples people redirect with getServerSideProps. But if I did this, wouldn't all of my pages would go from client side rendering to SSR, and I’m not sure if that would benefit me since I'm not interested in SEO. Although I’m not a fan of the loading page flash that occurs when a protected route is being client side redirected to the login page.
s
I’m having this exact same issue and it’s been driving me up the wall for months. I’m doing the same thing as you—redirecting to login or dashboard according to session/login state. I have no idea what to do about it.
@bim