Cannot redirect to redirectTo url when using the signInWithOAuth function
using @supabase/ssr
the login with password one works fine, but this one does not
I followed the guide for server side auth, and I can't get this client side oauth with google to work. For redirect, I've tried everything but it just defaults to the default that I had set in supabase. When I had this prior fully client side (with no server side auth), it worked. No idea how to fix this and help would be appreciated, thanks
24 Replies
Can you share a link to the doc you followed here please?
And then I couldn't figure out how to get the google oauth to work (that link only showed for simple user pass sign in)
You will have to continue with this guide to get this information https://supabase.com/docs/guides/auth/social-login/auth-google?queryGroups=environment&environment=server#signing-users-in
even if i follow that and have something like
it still redirects to a different url
@silentworks when i was just using client side, this worked
What do you mean by redirect to a different URL? please provide some concrete examples of what is happening as a user flow.
so my NEXT_PUBLIC_SITE_URL is localhost:3000
it is redirecting to the production site url
no matter what url i put in redirectTo
(for the first approach, when i did client side only it did redirect correctly)
This is rather confusing because I now don't know what first approach you are referring to
This one
This was only using client side
The one I am struggling is with now using server side auth
Are you using the same hosted Supabase instance for both local development and your production app?
yes
Firstly this is bad practice but if you do wish to continue this way, you need to add your localhost:3000 as a Redirect URL inside of your dashboard. https://supabase.com/dashboard/project/_/auth/url-configuration
Sure, but it already should be there if it worked when I was doing only client side auth right?
I don't know. Also if this works when you did the client side auth why are you changing it to server side?
because i need server side gating rather than client side
You need to make sure the exact URL is set in your Redirect URLs in the Supabase Dashboard, so it should be
http://localhost:3000/auth/callback. The client side version you said was working was only using http://localhost:3000.so why wouldn't the redirect work when i just tried redirect to localhsot:3000 then?
(adding the exact url did fix the issue though)
Because this is not the URL you have passed to
redirectTo in your code example for the server side setup.yeah, but even when I tried just passing the localhost:3000 it wasn't working
I think it's best to read the guide as I will only be reiterating what it covers here. But in the shortest format the ssr client requires an extra step in order to get you signed in which is what the page for
/auth/callback handles.does magic pasword link require this auth callback handle as well? or is it only the 3rd party oauth providers?
Magic link (otp) requires a
/auth/confirm as it uses a different method to the /auth/callback. It also requires an email template update, you can read more here https://supabase.com/docs/guides/auth/auth-email-passwordless?queryGroups=language&language=js#with-magic-linkGot it. Thank you very much
The Supabase UI docs cover some of these with code examples too https://supabase.com/ui/docs/getting-started/introduction
I also have a repo with code examples of all the flows in different frameworks, the Next example is not on the latest Next but it still works https://github.com/silentworks/supabase-by-example