Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emailRedirectTo not working on auth.updateUser #1262

Open
2 tasks done
dahjson opened this issue Aug 27, 2024 · 4 comments
Open
2 tasks done

emailRedirectTo not working on auth.updateUser #1262

dahjson opened this issue Aug 27, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@dahjson
Copy link

dahjson commented Aug 27, 2024

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

An open, unanswered discussion from nearly a year ago also addresses this issue:
GitHub Discussion #18810

Related documentation:
Supabase Auth UpdateUser

Describe the bug

When using the auth.updateUser function to change a user's email address, the emailRedirectTo parameter is expected to specify the URL to which the user is redirected after confirming the email change. However, this value does not carry over to the confirmation email link. Instead, the link always ends with the base site URL, ignoring the specified emailRedirectTo value.

To Reproduce

  1. Set localhost site URL and localhost wildcard for redirect URLs in supabase/config.toml
[auth]
site_url = "http://localhost:3000"
additional_redirect_urls = ["http://localhost:3000/**"]
  1. Set double email confirmations to false and enable email confirmations in supabase/config.toml
[auth.email]
double_confirm_changes = false
enable_confirmations = true
  1. Using .ConfirmationURL with HTML email template in supabase/templates/email_change.html
<p><a href="{{ .ConfirmationURL }}" target="_blank">Update Email</a></p>
  1. Use auth.updateUser to change the user's email.
const { data, error } = await supabase.auth.updateUser({
  email: '[email protected]',
  options: {
    emailRedirectTo: 'http://localhost:3000/settings',
  },
});

Expected behavior

Expected the emailRedirectTo value to carry over to the email link when using auth.updateUser, but it does not. Instead the link just always ends with http://localhost:3000/ in the email:
(e.g., ...&type=email_change&redirect_to=http://localhost:3000/)

System information

  • OS: macOS
  • Browser: Chrome
  • Version of supabase-js: 1.191.3
  • Version of Node.js: 20.16.0
@dahjson dahjson added the bug Something isn't working label Aug 27, 2024
@nassmim
Copy link

nassmim commented Oct 17, 2024

duplicate issue here: https://github.com/orgs/supabase/discussions/18810

@dahjson
Copy link
Author

dahjson commented Oct 20, 2024

duplicate issue here: https://github.com/orgs/supabase/discussions/18810

This is a related discussion. Not an actual issue.

@jrpersico
Copy link

jrpersico commented Nov 4, 2024

Hey @dahjson and @nassmim, this is working for me 👇

  1. Set localhost site URL and localhost wildcard for redirect URLs in supabase/config.toml
[auth]
site_url = "http://localhost:3000"
additional_redirect_urls = ["http://localhost:3000/**"]
  1. Use auth.updateUser to change the user's email.
const {data, error} = await supabase.auth.updateUser(
  {
    email: "[email protected]",
  },
  {
    emailRedirectTo: "http://localhost:3000/settings",
  }
);

@nassmim
Copy link

nassmim commented Nov 6, 2024

@jrpersico what did you enter in your email template for the "change email address"? As it also depends on it.

What I do have is:
the site url as : mydomain.com
the additional url: http://localhost:3002/**

and in my email template I have this: {{ .RedirectTo }}?token_hash={{ .TokenHash }}&type=email_change
Which does not work. I get redirected to the localhost as expected, but not to the right page specified in my emailRedirectTo

I would like the redirecto to work regardless of my siteurl variable, so both when i'm on local or when i'm on prod.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants