Clerk sign out issue with next.js
Sometimes, cloudflare pages + next.js turns out to be quite bad.
I am using clerk authenication and have a signout button.
On click of signout, it should redirect to signin page, but cloudflare get stucked without any errors.
On vercel same thing works fine.
Happy to share minimal reproducible code if anyone want to test out
7 Replies
A minimal reproduction would be very much appreciated. I'll try and see if I can find out what's going wrong on Monday (I'm travelling this weekend).
Thanks
Github repo: https://github.com/satpalsr/clerktest
Deployed on cloudflare pages: https://clerktest.pages.dev/
Deployed on vercel: https://clerktest-one.vercel.app/
If you want to deploy yourself on cloudflare, you need to add these env variables from https://clerk.com/
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
NODE_VERSION=19.9.0
I have also added
nodejs_compat
in Settings > Functions > Compatibility flagsI have another website (http://chatbrowser.io/) on cloudflare pages where sign in / sign out executes ok in Navigation bar. Even though in logs for signout I see.
But on a different page, the only different thing I am doing is using useEffect it gives same above error on signout but I get Error with some digest code on screen, in logs it's same.
The same website when deployed on vercel, log "warning" states for both sign in/ sign out but exectues alright.
So, everything is quite confusing.
Chat Browser
Chat with any URL you visit in Broswer
Apologies, I didn't get a chance to take a look today - some IRL stuff came up. Will try some things out tomorrow for sure though
I found out the problem only occurs when I route back to same page after signout.
It works fine when using router.push to a different page after signout
couldn't find any workaround or solution for visiting same page after signout
Though in every case, signout does happens. It's just that I have to manually press reload to get back to signin screen.
Found out a workaround: Started using router push to point to signin url instead of same url.
Hey there @reavatar, I am ever so sorry for the delay in a fix for this. I have traced back the problem to middleware redirects not always being returned to the client. I have opened a PR for a fix for this.
I would welcome you to try out the prerelease in https://github.com/cloudflare/next-on-pages/pull/386#issuecomment-1641061973
Thanks you much. I'll try it out with next package release.