I have a strange problem with the ``` supabase.aut...
# help
j
I have a strange problem with the
Copy code
supabase.auth.onAuthStateChange
not firing sometimes after a users clicks on a confirmation link, which makes my NextJS app not setting the authCookie correctly, causing the user to be redirected back to the sign in page. Anyone else came across this issue? 1. The user clicks on the confirmation link in the email 2. The user comes to my specified redirectUrl. 3. The onAuthStateChange-function, which lives in a context called useUser is not being fired at all, as I can't see the
Copy code
console.log(event)
firing at all. 4. The user goes to a different page, which has a getServerSideProps-function that checks if user exists on the server. If not, it redirects the user to the signin page
c
I don't use NextJS so I am NOT familiar with server-rendering specifics, but is it possible that the event fires BEFORE you've had a chance to subscribe to it?
(unfortunately, onAuthStateChanged currently does NOT guarantee at least one delivery of events, so if you subscribe AFTER the events have taken place, you are out of luck)
j
hmm yeah, that may be the issue
s
Haha I have the same issue with Sveltekit, the issue is that the server page is rendered before the client, so the cookie doesn't get set before the server does its check inside of getServerSide function. My current work around is to have a intermediate page which doesn't have a check on it, then redirect from that page to the one with the check on it, this little delay is enough for the cookie to be set and read.
j
ooh cool @User thanks for helping. could you just type down exactly how your user flows is right now? didn't exactly grasp the part with the intermediate page
My flow right now is that the user gets redirected to the /welcome-route after clicking on the verification link, that route doesn't have any checks on the user, but the problem occurs if the user is going to a different route than welcome, that does have a check in getServerSideProps, which then will redirect them to login page