rphlmr / supa-fly-stack

The Remix Stack for deploying to Fly with Supabase, authentication, testing, linting, formatting, etc.
MIT License
305 stars 27 forks source link

Question: Magic link is not working as expected #65

Closed DonKoko closed 1 year ago

DonKoko commented 1 year ago

We are having an issue with our magic link. I have tested this both in my localhost as well as on a fly.io environment.

Some more context:

Localhost

1 .Front-end works good, it sends the info

  1. Email is received
  2. Clicking on the email link gives a problem:

Screenshot 2023-02-17 at 13 25 27

When I inspect the link that comes in the email, there is some strange stuff I notice:

redirect_to=shelf-webapp.fly.dev/ I dont understand why this is the redirect url. I have double checked and on my localhost the SERVER_URL is set to localhost:3000. I also specifically debugged the function sendMagicLink and the SERVER_URL that is being sent is localhost:3000.

I am a bit lost and not sure why its not working.

Fly.io

Basically everything is the same like locahost except the url being wrong. The url in the link is correct, but we are still getting the same error in the browser, that no API key is found in the request.

Any help would be appreciated.

rphlmr commented 1 year ago

Hello,

This error seems to come from internal Supabase fetchWithAuth.

Can you confirm that SUPABASE_ANON_PUBLIC and SUPABASE_SERVICE_ROLE envs are correctly set?

Will check again if sendMagicLink still works as expected because the link should redirect to ${SERVER_URL}/oauth/callback where SERVER_URL is http://localhost:3000 on your machine and should be your fly.io server url on fly.

DonKoko commented 1 year ago

Can you confirm that SUPABASE_ANON_PUBLIC and SUPABASE_SERVICE_ROLE envs are correctly set?

Yes, i just double checked it. They are set correctly both in the fly.io env and in my local.

Will check again if sendMagicLink still works as expected because the link should redirect to ${SERVER_URL}/oauth/callback where SERVER_URL is http://localhost:3000 on your machine and should be your fly.io server url on fly.

Yeah indeed thats what i figured out from inspecting the code and as mentioned i also double checked that the SERVER_URL is set correctly and it points to localhost:300

rphlmr commented 1 year ago

I'm waiting for a fly cli update (the last version available has issues :'( ) and I will deploy a demo to check on my side ;)

rphlmr commented 1 year ago

Ok, I may have missed something in the documentation 🥲.

CleanShot 2023-02-17 at 18 44 04

On your Supabase dashboard, can you enable Redirect URLs and tell me if it solves your issue?

Without that, the magic link redirect_to value fallback to Supabase's "Site URL"

rphlmr commented 1 year ago

This is a temporary demo hosted on fly: https://supa-fly-stack-template-rphlmr.fly.dev (will delete it in 24h because I have no more credits 😇)

DonKoko commented 1 year ago

Thanks @rphlmr. I just had time to do a quick test with your url and it worked as expected. Will test it on our own env tomorrow and close the issue if it all works good.

DonKoko commented 1 year ago

I can confirm everything worked as expected. Thanks for the help.