I cannot logout of supabase auth
I'm running nextjs and integrating with supabase auth. I have been able to login and signup users but I cannot logout. I've tried over and over again. I switched over to clerk which is a great product and have had no problem with it. However, I came back to supabase thinking I could actually make this work. I can't.
I've followed supabase docs to the letter and i cannot make logout work. I've searched for example repositories that provide working examples of login and logout. Here's one:
https://github.com/SamuelSackey/nextjs-supabase-example/tree/main
I cloned this local, set my supa anon key and url and sure enough, i see the logged in status of my supabase user but clicking the logout button does nothing???
Maybe I should spin up a brand new supabase instance? Tired of beating my head against the wall. Would love to know if this example repo works for anyone else.
GitHub
GitHub - SamuelSackey/nextjs-supabase-example: Next.js example proj...
Next.js example project for setting up Supabase Google OAuth, middleware, protected routes, and dynamic rendering for beginners - SamuelSackey/nextjs-supabase-example
12 Replies
do you get any error in the console?
I see this template has a
logout-button
component, you can try setting a try/catch block on the handleLogout
funtion, and see if you get an error therethis example works:
https://github.com/SarathAdhi/next-supabase-auth/blob/main/src/app/actions.ts
i'm assuming it's some client side conflict but i'm not sure why the docs don't make this obvious or why there's not a working end-to-end example from supabase
GitHub
next-supabase-auth/src/app/actions.ts at main · SarathAdhi/next-sup...
Next.js 14 (app router) with Supabase Authentication and Shadcn - Starter Template - SarathAdhi/next-supabase-auth
yeah, is a different implementation
and there is a working end-to-end example of Supabase/NextJS https://supabase.com/docs/guides/getting-started/tutorials/with-nextjs
Build a User Management App with Next.js | Supabase Docs
Learn how to use Supabase in your Next.js App.
LOL that's the example that i worked through...before I gave up...turned to reddit which convinced me to switch to clerk
this example works because:
signOut is served up via api route
i guess that's best practice eh?
yeah, same as the last template you share, it also uses the server side code with the server action
right...that's my hang up right or wrong
clerk client side logout works:
i'll stick with supa auth since this now works and I get why...but wish it was more obvious
I see, and I understand what you mean... NextJS has/is changing so much that I imagine it will take some time for companies like supabase to standardize things, for example SSR/client side stuff...
I think a good rule of thumb would be to always use server side ssr for auth stuff, since this works with cookies/sessions... I imagine the issue in the client side with the first template is that is not clearing our the session properly
but glad to know its working for you now and you will stick with supabase 😄
same...glad i can rely on supabase and not have to add one more thing...
thx @Tomás P.
Have you used our official example?
npx create-next-app -e with-supabase
even if you set that up in a another folder somewhere it should help you copy what we're doing there into your own
I see that guide tells you to use
npx create-next-app@latest --use-npm supabase-nextjs
— I haven't done a run through of this in a long time, I'll give it a try next week.
I'd look for inspiration from this one, it's very up to date. Should be able to get you rolling pretty quick.
npx create-next-app -e with-supabase
thanks, giving it a try now
this works, no issues @Terry thx
Great! Need to update that guide next week.