question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`redirectTo` not being respected when using email or magic link auth

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Reactions:6
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
TheThirdRacecommented, Dec 20, 2021

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.

1reaction
lack-of-gravitascommented, Aug 15, 2022

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.

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Site URL path not respected on localhost with third-party ...
Go to Project > Authentication > Settings (tab); Edit the Site URL to be localhost:3000/[path] . Perform login via third-party provider with ......
Read more >
Redirect to my site after a user clicks the magic link - Helpdesk
On the redirect page, call await magic. auth. loginWithCredential(); which will grab and return the DID token from the query parameters which ...
Read more >
Frequently Asked Questions - Documentation - Magic.link
If no redirect is specified, the user will see a confirmation screen telling them to go back to the original tab where they...
Read more >
Redirect to URL from magic link - Auth0 Community
Can we customize the magic link at all so that the user is redirected to a particular resource (document) in our app? How...
Read more >
Use redirect auth with the Identity Engine sample apps | Okta ...
Try the email magic link recovery flow: Select Forgot password? in the Sign-In Widget. Enter your email or username when prompted and click...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found