You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|`{{ .ConfirmationURL }}`| Contains the confirmation URL. For example, a signup confirmation URL would look like: `https://project-ref.supabase.co/auth/v1/verify?token={{ .TokenHash }}&type=email&redirect_to=https://example.com/path` .|
22
-
|`{{ .Token }}`| Contains a 6-digit One-Time-Password (OTP) that can be used instead of the `{{. ConfirmationURL }}` .|
36
+
|`{{ .ConfirmationURL }}`| Contains the confirmation URL. For example, a signup confirmation URL would look like: `https://project-ref.supabase.co/auth/v1/verify?token={{ .TokenHash }}&type=email&redirect_to=https://example.com/path`. |
37
+
|`{{ .Token }}`| Contains a 6-digit One-Time-Password (OTP) that can be used instead of the `{{. ConfirmationURL }}`. |
23
38
|`{{ .TokenHash }}`| Contains a hashed version of the `{{ .Token }}`. This is useful for constructing your own email link in the email template. |
24
39
|`{{ .SiteURL }}`| Contains your application's Site URL. This can be configured in your project's [authentication settings](/dashboard/project/_/auth/url-configuration). |
25
40
|`{{ .RedirectTo }}`| Contains the redirect URL passed when `signUp`, `signInWithOtp`, `signInWithOAuth`, `resetPasswordForEmail` or `inviteUserByEmail` is called. The redirect URL allow list can be configured in your project's [authentication settings](/dashboard/project/_/auth/url-configuration). |
26
41
|`{{ .Data }}`| Contains metadata from `auth.users.user_metadata`. Use this to personalize the email message. |
27
42
|`{{ .Email }}`| Contains the original email address of the user. Empty when when trying to [link an email address to an anonymous user](/docs/guides/auth/auth-anonymous#link-an-email--phone-identity). |
28
-
|`{{ .NewEmail }}`| Contains the new email address of the user. This variable is only supported in the "Change Email Address" template. |
43
+
|`{{ .NewEmail }}`| Contains the new email address of the user. This variable is only supported in the "Change email address" template. |
44
+
|`{{ .OldEmail }}`| Contains the old email address of the user. This variable is only supported in the "Email address changed notification" template. |
45
+
|`{{ .Phone }}`| Contains the new phone number of the user. This variable is only supported in the "Phone number changed notification" template. |
46
+
|`{{ .OldPhone }}`| Contains the old phone address of the user. This variable is only supported in the "Phone number changed notification" template. |
47
+
|`{{ .Provider }}`| Contains the provider of the newly linked/unlinked identity. This variable is only supported in the "Identity linked notification" and "Identity unlinked notification" templates. |
48
+
|`{{ .FactorType }}`| Contains the type of the newly enrolled/unenrolled MFA method. This variable is only supported in the "MFA method added notification" and "MFA method removed notification" templates. |
"mailer_templates_recovery_content": "<h2>Reset Password</h2><p>Follow this link to reset the password for your user:</p><p><a href=\"{{ .ConfirmationURL }}\">Reset Password</a></p>",
57
77
"mailer_subjects_invite": "You have been invited",
58
78
"mailer_templates_invite_content": "<h2>You have been invited</h2><p>You have been invited to create a user on {{ .SiteURL }}. Follow this link to accept the invite:</p><p><a href=\"{{ .ConfirmationURL }}\">Accept the invite</a></p>",
"mailer_templates_email_change_content": "<h2>Confirm email change</h2><p>Follow this link to confirm the update of your email:</p><p><a href=\"{{ .ConfirmationURL }}\">Change email</a></p>",
"mailer_subjects_password_changed_notification": "Your password has been changed",
85
+
"mailer_templates_password_changed_notification_content": "<h2>Your password has been changed</h2>\n\n<p>This is a confirmation that the password for your account {{ .Email }} has just been changed.</p>\n<p>If you did not make this change, please contact support.</p>",
"mailer_subjects_email_changed_notification": "Your email address has been changed",
88
+
"mailer_templates_email_changed_notification_content": "<h2>Your email address has been changed</h2>\n\n<p>The email address for your account has been changed from {{ .OldEmail }} to {{ .Email }}.</p>\n<p>If you did not make this change, please contact support.</p>",
"mailer_subjects_phone_changed_notification": "Your phone number has been changed",
91
+
"mailer_templates_phone_changed_notification_content": "<h2>Your phone number has been changed</h2>\n\n<p>The phone number for your account {{ .Email }} has been changed from {{ .OldPhone }} to {{ .Phone }}.</p>\n<p>If you did not make this change, please contact support immediately.</p>",
"mailer_subjects_mfa_factor_enrolled_notification": "A new MFA factor has been enrolled",
94
+
"mailer_templates_mfa_factor_enrolled_notification_content": "<h2>A new MFA factor has been enrolled</h2>\n\n<p>A new factor ({{ .FactorType }}) has been enrolled for your account {{ .Email }}.</p>\n<p>If you did not make this change, please contact support immediately.</p>",
"mailer_subjects_mfa_factor_unenrolled_notification": "An MFA factor has been unenrolled",
97
+
"mailer_templates_mfa_factor_unenrolled_notification_content": "<h2>An MFA factor has been unenrolled</h2>\n\n<p>A factor ({{ .FactorType }}) has been unenrolled for your account {{ .Email }}.</p>\n<p>If you did not make this change, please contact support immediately.</p>",
"mailer_subjects_identity_linked_notification": "A new identity has been linked",
100
+
"mailer_templates_identity_linked_notification_content": "<h2>A new identity has been linked</h2>\n\n<p>A new identity ({{ .Provider }}) has been linked to your account {{ .Email }}.</p>\n<p>If you did not make this change, please contact support immediately.</p>",
"mailer_subjects_identity_unlinked_notification": "An identity has been unlinked",
103
+
"mailer_templates_identity_unlinked_notification_content": "<h2>An identity has been unlinked</h2>\n\n<p>An identity ({{ .Provider }}) has been unlinked from your account {{ .Email }}.</p>\n<p>If you did not make this change, please contact support immediately.</p>"
Copy file name to clipboardExpand all lines: apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx
+77-46Lines changed: 77 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,55 +1,17 @@
1
1
---
2
2
id: 'send-email-hook'
3
3
title: 'Send Email Hook'
4
-
subtitle: 'Use a custom email provider to send authentication messages'
4
+
subtitle: 'Use a custom email provider to send authentication messages.'
5
5
---
6
6
7
-
The Send Email Hook runs before an email is sent and allows for flexibility around email sending. You can use this hook to configure a back-up email provider or add internationalization to your emails.
8
-
9
-
## Email sending behavior
10
-
11
-
Email sending depends on two settings: Email Provider and Auth Hook status.
When `email_action_type` is `email_change`, the hook payload can include one or two OTPs and their hashes. This depends on your [Secure Email Change](/dashboard/project/_/auth/providers?provider=Email) setting.
23
-
24
-
- Secure Email Change enabled: two OTPs are generated, one for the current email (`user.email`) and one for the new email (`user.email_new`). You must send two emails.
25
-
- Secure Email Change disabled: only one OTP is generated for the new email. You send a single email.
This naming is historical and kept for backward compatibility. Do not assume that the `_new` suffix refers to the new email.
35
-
36
-
</Admonition>
37
-
38
-
### What to send
39
-
40
-
If both `token_hash` and `token_hash_new` are present, send two messages:
41
-
42
-
- To the current email (`user.email`): use `token` with `token_hash_new`.
43
-
- To the new email (`user.email_new`): use `token_new` with `token_hash`.
44
-
45
-
If only one token/hash pair is present, send a single email. In non-secure mode, this is typically the new email OTP. Use `token` with `token_hash` or `token_new` with `token_hash`, depending on which fields are present in the payload.
7
+
The Send Email Hook runs before an email is sent and allows for flexibility around email sending. You can use this hook to configure a backup email provider or to add internationalization to your emails.
When `email_action_type` is `email_change`, the hook payload can include one or two OTPs and their hashes. This depends on your [Secure Email Change](/dashboard/project/_/auth/providers?provider=Email) setting.
370
+
371
+
- Secure Email Change enabled: two OTPs are generated, one for the current email (`user.email`) and one for the new email (`user.email_new`). You must send two emails.
372
+
- Secure Email Change disabled: only one OTP is generated for the new email. You send a single email.
373
+
374
+
<Admonitiontype="caution"title="Counterintuitive field naming">
375
+
376
+
The token hash field names are reversed due to backward compatibility. Pay careful attention to which token/hash pair goes with which email address:
377
+
378
+
-`token_hash_new` → use with the **current** email address (`user.email`) and `token`
379
+
-`token_hash` → use with the **new** email address (`user.email_new`) and `token_new`
380
+
381
+
Do not assume the `_new` suffix refers to the new email address.
382
+
383
+
</Admonition>
384
+
385
+
### What to send
386
+
387
+
When Secure Email Change is enabled (both token/hash pairs present):
388
+
389
+
- Send to **current** email address (`user.email`): use `token` with `token_hash_new`
390
+
- Send to **new** email address (`user.email_new`): use `token_new` with `token_hash`
391
+
392
+
When Secure Email Change is **disabled** (only one token/hash pair present):
393
+
394
+
- Send a single email to the **new** email address. Use `token` with `token_hash` or `token_new` with `token_hash`, depending on which fields are present in the payload.
0 commit comments