KolbySisk/next-supabase-stripe-starter

Auth not working

pnandha opened this issue ยท 4 comments

Hey Fantastic job with the repo.

However when the email returns a link and I click it, it doesn't seem to authenticate.

Any Ideas ? I see the code in the URL but then nothing happens.

Screenshot 2024-08-28 at 15 39 51

The return URL doesn't look correct. It should be going to /auth/callback

You can see the associated code here: https://github.com/KolbySisk/next-supabase-stripe-starter/blob/main/src/app/(auth)/auth/callback/route.ts

And this is where it redirects to that route: https://github.com/KolbySisk/next-supabase-stripe-starter/blob/main/src/app/(auth)/auth-actions.ts

Try updating your redirect URL in Supabase to include http://localhost:3000/auth/callback
https://supabase.com/docs/guides/auth/redirect-urls

Let me know if you get it working

Hi there @KolbySisk, I am running into this issue as well. I'm relatively new to Supabase auth so I am trying to figure this out as well. Is this how the Supabase URL needs to be set up?

Authentication  Supabase-2024-09-05-22 52 38@2x

When clicking this link now from my email it takes me to my Vercel URL, not my localhost. However when I head back to localhost it recognizes me as logged in.

This fixes this for me for now but would ultimately want to make sure I have this set up correctly in the long haul. Happy to help with documentation, code comments, or anything else to help newbies getting up and running with this.

@pnandha I think I figured this out. I needed to set the NEXT_PUBLIC_SITE_URL in my .env.local to http://localhost:3000. This set the authActions.js file with all the helpers in it to use getUrl correctly to properly set /auth/callback to work as the redirect.

@RobErskine Happy to hear you figured it out.

I see the problem now. The redirect uses the getURL util function which looks for the NEXT_PUBLIC_SITE_URL and when not found falls back to localhost:3000. The intention here was that this var wouldn't be set locally and so it would always fall back.

But I merged this PR: #3 which sets the NEXT_PUBLIC_SITE_URL to a bad default. I should have paid closer attention. I think an easy fix here is to set the var to localhost:3000 locally.

Thanks for the help.