In development, when I try to sign in using magic ...
# help
m
In development, when I try to sign in using magic link, it always redirects me to the production app and authenticates there instead. Is there some way to use magic-link sign-in in development? So far, the best (hacky) workaround I've found is manually pasting the production auth token into my localhost's localStorage to authenticate...
n
Hello @Mike_! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
g
You might look at this. Seems you can add localhost to the redirect urls list and use redirectTo option in the signIn. Don't think that would work for the magic link button in the auth window on the dashboard. I've not tried this. https://github.com/supabase/supabase/discussions/600
b
Just add the redirectTo parameter.
Let me dig up my example.
Copy code
const { user, session, error } = await supabase.auth.signIn({
      email: email
    }, {
      redirectTo: window.location.origin
    });
    return { user, session, error };
Just make sure to whitelist your localhost url in the Supabase dashboard. Now you can send magic links in production and in local development and you'll get redirected to the correct place.
m
Ahhh brilliant! I'll give this another try. I tried using the redirectTo param yesterday but used it incorrectly:
Copy code
js
// wrong
supabase.auth.signIn({
    email: email,
    redirectTo: window.location.origin
})
b
Another important note: as of about a week ago, you can use wildcards in your whitelisted URLs in the dashboard, so you can say: http://localhost:3000/** (using glob syntax) to allow any URL that starts with http://localhost:3000. Or just a single * to denote a wildcard, so if you use http://localhost:3000/* that would allow http://localhost:3000/abc but not http://localhost:3000/abc/123.
m
Oooh this will save me some pain... I had
http://localhost:3000/*
set up instead of the double
Thanks for the heads up
Works like a charm 🙏
n
Thread was archived by @Mike_. Anyone can send a message to unarchive it.