`redirectTo` not being respected when using email or magic link auth
See original GitHub issueBug report
Describe the bug
I’ve been stuck on this for hours and thought to finally reach out. It looks like there are a bunch of old bug reports that indicate this should be working now but I haven’t been able to get it to work.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
const { error } = await supabase.auth.signIn(
{ email, password },
{ redirectTo: 'http://localhost:3000/dashboard' },
);
I have http://localhost:3000/dashboard configured as an Additional Redirect URL on my Supabase project settings. I see the redirect_to
parameter in the /auth/v1/token request to Supabase but I always get bounced back to http://localhost:3000 and not the dashboard page.
Expected behavior
redirectTo
would go to the expected page.
Screenshots
Not sure how helpful screenshots would be, but I can see that the referrer to the request back to index is http://localhost:3000/signin. I’ve tried putting breakpoints on the GoTrue client code but the decision on where to redirect appears to happen on the server.
System information
- OS: mac
- Browser (if applies) chrome
- Version of supabase-js:
"@supabase/supabase-js": "^1.28.5",
- Version of Node.js: 16.2.0
- Version of Next.js:
"next": "^12.0.7",
Additional context
In general the Supabase auth docs could use some love. They are really high level but don’t provide a lot of details so I ended up just following a lot of the example code and things seem iffy at best. Maybe it’s the Next.js integration? My users get logged out all of the time–perhaps I need to extend the JWT expiration? Having some examples showing persistent session would be appreciated or examples of how supabase.io handles auth so I don’t have to enter my credentials every day.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:14 (5 by maintainers)
I would love for the Magic Link to respect the
redirectTo
.When a user is in a page accessible from a long/deep route, ex:
XXXX/XX/XXXX/XX/XXXX/XX/XXXX/XX/
, it’s no fun at all to be redirected back to the home page…All the providers are redirecting to the correct page, only Magic Links are stuck on the home page only.
Yes @J0 this is the behaviour we expect – I did exactly that and that works now too. Thank you again for the quick around… much love to Supabase Team.
Might be overkill but here’s what I’ve got as redirects in Supabase Auth configuration screen for any future people struggling with this.