Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(docs): add account changes notifications email customization (#40141)

issuedatf10f76e7e47b
diff --git a/apps/docs/content/guides/auth/auth-email-templates.mdx b/apps/docs/content/guides/auth/auth-email-templates.mdx
index 7731d4f990a..2d13408de00 100644
--- a/apps/docs/content/guides/auth/auth-email-templates.mdx
+++ b/apps/docs/content/guides/auth/auth-email-templates.mdx
@@ -4,13 +4,28 @@ description: 'Learn how to manage the email templates in Supabase.'
subtitle: 'Learn how to manage the email templates in Supabase.'
---
-You can customize the email messages used for the authentication flows. You can edit the following email templates:
+Email templates in Supabase fall into two categories: authentication and security notifications.
-- Confirm signup
+Authentication emails:
+
+- Confirm sign up
- Invite user
-- Magic Link
-- Change Email Address
-- Reset Password
+- Magic link
+- Change email address
+- Reset password
+- Reauthentication
+
+Security notification emails:
+
+- Password changed
+- Email address changed
+- Phone number changed
+- Identity linked
+- Identity unlinked
+- Multi-factor authentication (MFA) method added
+- Multi-factor authentication (MFA) method removed
+
+Security emails are only sent to users if the respective security notifications have been enabled at a project-level.
## Terminology
@@ -18,14 +33,19 @@ The templating system provides the following variables for use:
| Name | Description |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `{{ .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` . |
-| `{{ .Token }}` | Contains a 6-digit One-Time-Password (OTP) that can be used instead of the `{{. ConfirmationURL }}` . |
+| `{{ .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`. |
+| `{{ .Token }}` | Contains a 6-digit One-Time-Password (OTP) that can be used instead of the `{{. ConfirmationURL }}`. |
| `{{ .TokenHash }}` | Contains a hashed version of the `{{ .Token }}`. This is useful for constructing your own email link in the email template. |
| `{{ .SiteURL }}` | Contains your application's Site URL. This can be configured in your project's [authentication settings](/dashboard/project/_/auth/url-configuration). |
| `{{ .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). |
| `{{ .Data }}` | Contains metadata from `auth.users.user_metadata`. Use this to personalize the email message. |
| `{{ .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). |
-| `{{ .NewEmail }}` | Contains the new email address of the user. This variable is only supported in the "Change Email Address" template. |
+| `{{ .NewEmail }}` | Contains the new email address of the user. This variable is only supported in the "Change email address" template. |
+| `{{ .OldEmail }}` | Contains the old email address of the user. This variable is only supported in the "Email address changed notification" template. |
+| `{{ .Phone }}` | Contains the new phone number of the user. This variable is only supported in the "Phone number changed notification" template. |
+| `{{ .OldPhone }}` | Contains the old phone address of the user. This variable is only supported in the "Phone number changed notification" template. |
+| `{{ .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. |
+| `{{ .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. |
## Editing email templates
@@ -56,8 +76,31 @@ curl -X PATCH "https://api.supabase.com/v1/projects/$PROJECT_REF/config/auth" \
"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>",
"mailer_subjects_invite": "You have been invited",
"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_subjects_reauthentication": "Confirm reauthentication",
+ "mailer_templates_reauthentication_content": "<h2>Confirm reauthentication</h2><p>Enter the code: {{token}}</p>",
"mailer_subjects_email_change": "Confirm email change",
"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_notifications_password_changed_enabled": true,
+ "mailer_subjects_password_changed_notification": "Your password has been changed",
+ "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_notifications_email_changed_enabled": true,
+ "mailer_subjects_email_changed_notification": "Your email address has been changed",
+ "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_notifications_phone_changed_enabled": true,
+ "mailer_subjects_phone_changed_notification": "Your phone number has been changed",
+ "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_notifications_mfa_factor_enrolled_enabled": true,
+ "mailer_subjects_mfa_factor_enrolled_notification": "A new MFA factor has been enrolled",
+ "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_notifications_mfa_factor_unenrolled_enabled": true,
+ "mailer_subjects_mfa_factor_unenrolled_notification": "An MFA factor has been unenrolled",
+ "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_notifications_identity_linked_enabled": true,
+ "mailer_subjects_identity_linked_notification": "A new identity has been linked",
+ "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_notifications_identity_unlinked_enabled": true,
+ "mailer_subjects_identity_unlinked_notification": "An identity has been unlinked",
+ "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>"
}'
```
diff --git a/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx b/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx
index 7b765a018ca..4bbeb479a64 100644
--- a/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx
+++ b/apps/docs/content/guides/auth/auth-hooks/send-email-hook.mdx
@@ -1,55 +1,17 @@
---
id: 'send-email-hook'
title: 'Send Email Hook'
-subtitle: 'Use a custom email provider to send authentication messages'
+subtitle: 'Use a custom email provider to send authentication messages.'
---
-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.
-
-## Email sending behavior
-
-Email sending depends on two settings: Email Provider and Auth Hook status.
-
-| Email Provider | Auth Hook | Result |
-| -------------- | --------- | -------------------------------------------------------------------- |
-| Enabled | Enabled | Auth Hook handles email sending (SMTP not used) |
-| Enabled | Disabled | SMTP handles email sending (custom if configured, default otherwise) |
-| Disabled | Enabled | Email Signups Disabled |
-| Disabled | Disabled | Email Signups Disabled |
-
-## Email change behavior and token hash mapping
-
-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.
-
-- 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.
-- Secure Email Change disabled: only one OTP is generated for the new email. You send a single email.
-
-<Admonition type="note">
-
-Important quirk (backward compatibility):
-
-- `email_data.token_hash_new` = Hash(`user.email`, `email_data.token`)
-- `email_data.token_hash` = Hash(`user.email_new`, `email_data.token_new`)
-
-This naming is historical and kept for backward compatibility. Do not assume that the `_new` suffix refers to the new email.
-
-</Admonition>
-
-### What to send
-
-If both `token_hash` and `token_hash_new` are present, send two messages:
-
-- To the current email (`user.email`): use `token` with `token_hash_new`.
-- To the new email (`user.email_new`): use `token_new` with `token_hash`.
-
-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.
+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.
**Inputs**
-| Field | Type | Description |
-| ------- | ------------------------------------------------- | ---------------------------------------------------------------------------------- |
-| `user` | [`User`](/docs/guides/auth/users#the-user-object) | The user attempting to sign in. |
-| `email` | `object` | Metadata specific to the email sending process. Includes the OTP and `token_hash`. |
+| Field | Type | Description |
+| ------- | ------------------------------------------------- | ---------------------------------------------- |
+| `user` | [`User`](/docs/guides/auth/users#the-user-object) | The user account taking the action |
+| `email` | `object` | Metadata specific to the email sending process |
<Tabs
scrollable
@@ -105,7 +67,11 @@ If only one token/hash pair is present, send a single email. In non-secure mode,
"email_action_type": "signup",
"site_url": "http://localhost:9999",
"token_new": "",
- "token_hash_new": ""
+ "token_hash_new": "",
+ "old_email": "",
+ "old_phone": "",
+ "provider": "",
+ "factor_type": ""
}
}
```
@@ -316,7 +282,14 @@ If only one token/hash pair is present, send a single email. In non-secure mode,
"recovery",
"email_change",
"email",
- "reauthentication"
+ "reauthentication",
+ "password_changed_notification",
+ "email_changed_notification",
+ "phone_changed_notification",
+ "identity_linked_notification",
+ "identity_unlinked_notification",
+ "mfa_factor_enrolled_notification",
+ "mfa_factor_unenrolled_notification"
]
},
"site_url": {
@@ -338,6 +311,24 @@ If only one token/hash pair is present, send a single email. In non-secure mode,
"x-faker": {
"fake": "{{random.alphaNumeric(30)}}"
}
+ },
+ "old_email": {
+ "type": "string",
+ "x-faker": "internet.email"
+ },
+ "old_phone": {
+ "type": "string",
+ "x-faker": {
+ "fake": "{{phone.phoneNumber('+1##########')}}"
+ }
+ },
+ "provider": {
+ "type": "string",
+ "enum": ["email"]
+ },
+ "factor_type": {
+ "type": "string",
+ "enum": ["totp"]
}
},
"required": [
@@ -362,6 +353,46 @@ If only one token/hash pair is present, send a single email. In non-secure mode,
- No outputs are required. An empty response with a status code of 200 is taken as a successful response.
+## Email sending behavior
+
+Email sending depends on two settings: Email Provider and Auth Hook status.
+
+| Email Provider | Auth Hook | Result |
+| -------------- | --------- | -------------------------------------------------------------------- |
+| Enabled | Enabled | Auth Hook handles email sending (SMTP not used) |
+| Enabled | Disabled | SMTP handles email sending (custom if configured, default otherwise) |
+| Disabled | Enabled | Email signups disabled |
+| Disabled | Disabled | Email signups disabled |
+
+## Email change behavior and token hash mapping
+
+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.
+
+- 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.
+- Secure Email Change disabled: only one OTP is generated for the new email. You send a single email.
+
+<Admonition type="caution" title="Counterintuitive field naming">
+
+The token hash field names are reversed due to backward compatibility. Pay careful attention to which token/hash pair goes with which email address:
+
+- `token_hash_new` → use with the **current** email address (`user.email`) and `token`
+- `token_hash` → use with the **new** email address (`user.email_new`) and `token_new`
+
+Do not assume the `_new` suffix refers to the new email address.
+
+</Admonition>
+
+### What to send
+
+When Secure Email Change is enabled (both token/hash pairs present):
+
+- Send to **current** email address (`user.email`): use `token` with `token_hash_new`
+- Send to **new** email address (`user.email_new`): use `token_new` with `token_hash`
+
+When Secure Email Change is **disabled** (only one token/hash pair present):
+
+- 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.
+
<Tabs
scrollable
size="small"
diff --git a/apps/docs/content/guides/local-development/customizing-email-templates.mdx b/apps/docs/content/guides/local-development/customizing-email-templates.mdx
index 0935886c4f5..60bcb1ea69e 100644
--- a/apps/docs/content/guides/local-development/customizing-email-templates.mdx
+++ b/apps/docs/content/guides/local-development/customizing-email-templates.mdx
@@ -1,15 +1,16 @@
---
id: 'customizing-email-templates'
title: 'Customizing email templates'
-description: 'Customizing local email templates using config.toml.'
-subtitle: 'Customizing local email templates using config.toml.'
+subtitle: 'Customize local email templates via the config file.'
---
-You can customize the email templates for local development [using the `config.toml` settings](/docs/guides/cli/config#auth-config).
+You can customize the email templates for local development by [editing the `config.toml` file](/docs/guides/local-development/cli/config#auth-config).
## Configuring templates
-You should provide a relative URL to the `content_path` parameter, pointing to an HTML file which contains the template. For example
+You should provide a relative URL to the `content_path` parameter, pointing to an HTML file which contains the template. For example:
+
+### Authentication email templates
<$CodeTabs>
@@ -30,52 +31,129 @@ content_path = "./supabase/templates/invite.html"
</$CodeTabs>
-## Available email templates
+### Security notification email templates
+
+<$CodeTabs>
-There are several Auth email templates which can be configured. Each template serves a specific authentication flow:
+```toml name=supabase/config.toml
+[auth.email.notification.password_changed]
+enabled = true
+subject = "Your password has been changed"
+content_path = "./templates/password_changed_notification.html"
+```
+
+```html name=templates/password_changed_notification.html
+<html>
+ <body>
+ <p>
+ This is a confirmation that the password for your account {{ .Email }} has just been changed.
+ </p>
+ <p>If you did not make this change, please contact support.</p>
+ </body>
+</html>
+```
+
+</$CodeTabs>
+
+## Available authentication email templates
+
+There are several authentication-related email templates which can be configured. Each template serves a specific authentication flow:
### `auth.email.template.invite`
**Default subject**: "You have been invited"
**When sent**: When a user is invited to join your application via email invitation
-**Purpose**: Allows administrators to invite users who don't have accounts yet
+**Purpose**: Invite users who don't yet have an account to sign up
**Content**: Contains a link for the invited user to accept the invitation and create their account
### `auth.email.template.confirmation`
**Default subject**: "Confirm Your Signup"
**When sent**: When a user signs up and needs to verify their email address
-**Purpose**: Email verification for new user registrations
+**Purpose**: Ask users to confirm their email address after signing up
**Content**: Contains a confirmation link to verify the user's email address
### `auth.email.template.recovery`
**Default subject**: "Reset Your Password"
**When sent**: When a user requests a password reset
-**Purpose**: Password recovery flow for users who forgot their password
+**Purpose**: Allow users to reset their password if they forget it
**Content**: Contains a link to reset the user's password
### `auth.email.template.magic_link`
**Default subject**: "Your Magic Link"
**When sent**: When a user requests a magic link for passwordless authentication
-**Purpose**: Passwordless login using email links
+**Purpose**: Allow users to sign in via a one-time link sent to their email
**Content**: Contains a secure link that automatically logs the user in when clicked
### `auth.email.template.email_change`
**Default subject**: "Confirm Email Change"
**When sent**: When a user requests to change their email address
-**Purpose**: Verification for email address changes
+**Purpose**: Ask users to verify their new email address after changing it
**Content**: Contains a confirmation link to verify the new email address
### `auth.email.template.reauthentication`
**Default subject**: "Confirm Reauthentication"
**When sent**: When a user needs to re-authenticate for sensitive operations
-**Purpose**: Additional verification for sensitive actions (like changing password, deleting account)
+**Purpose**: Ask users to re-authenticate before performing a sensitive action
**Content**: Contains a 6-digit OTP code for verification
+## Available security notification email templates
+
+There are several security notification email templates which can be configured. These emails are only sent to users if the respective security notifications have been enabled at the project-level:
+
+### `auth.email.notification.password_changed`
+
+**Default subject**: "Your password has been changed"
+**When sent**: When a user's password is changed
+**Purpose**: Notify users when their password has changed
+**Content**: Confirms that the password for the account has been changed
+
+### `auth.email.notification.email_changed`
+
+**Default subject**: "Your email address has been changed"
+**When sent**: When a user's email address is changed
+**Purpose**: Notify users when their email address has changed
+**Content**: Confirms the change from the old email to the new email address
+
+### `auth.email.notification.phone_changed`
+
+**Default subject**: "Your phone number has been changed"
+**When sent**: When a user's phone number is changed
+**Purpose**: Notify users when their phone number has changed
+**Content**: Confirms the change from the old phone number to the new phone number
+
+### `auth.email.notification.mfa_factor_enrolled`
+
+**Default subject**: "A new MFA factor has been enrolled"
+**When sent**: When a new MFA factor is added to the user's account
+**Purpose**: Notify users when a new multi-factor authentication method has been added to their account
+**Content**: Confirms that a new MFA factor type has been enrolled
+
+### `auth.email.notification.mfa_factor_unenrolled`
+
+**Default subject**: "An MFA factor has been unenrolled"
+**When sent**: When an MFA factor is removed from the user's account
+**Purpose**: Notify users when a multi-factor authentication method has been removed from their account
+**Content**: Confirms that an MFA factor type has been unenrolled
+
+### `auth.email.notification.identity_linked`
+
+**Default subject**: "A new identity has been linked"
+**When sent**: When a new identity is linked to the account
+**Purpose**: Notify users when a new identity has been linked to their account
+**Content**: Confirms that a new identity has been linked
+
+### `auth.email.notification.identity_unlinked`
+
+**Default subject**: "An identity has been unlinked"
+**When sent**: When an identity has been unlinked from the account
+**Purpose**: Notify users when an identity has been unlinked from their account
+**Content**: Confirms that an identity has been unlinked
+
## Template variables
The templating system provides the following variables for use:
@@ -149,6 +227,56 @@ Contains the new user's email address. This is only available in the `email_chan
<p>You are requesting to update your email address to {{ .NewEmail }}.</p>
```
+### `OldEmail`
+
+Contains the user's old email address. This is only available in the `email_changed_notification` email template.
+
+**Usage**
+
+```html
+<p>The email address for your account has been changed from {{ .OldEmail }} to {{ .Email }}.</p>
+```
+
+### `Phone`
+
+Contains the user's new phone number. This is only available in the `phone_changed_notification` email template.
+
+**Usage**
+
+```html
+<p>The phone number for your account has been changed from {{ .OldPhone }} to {{ .Phone }}.</p>
+```
+
+### `OldPhone`
+
+Contains the user's old phone number. This is only available in the `phone_changed_notification` email template.
+
+**Usage**
+
+```html
+<p>The phone number for your account has been changed from {{ .OldPhone }} to {{ .Phone }}.</p>
+```
+
+### `Provider`
+
+Contains the provider of the newly linked/unlinked identity. This is only available in the `identity_linked_notification` and `identity_unlinked_notification` email templates.
+
+**Usage**
+
+```html
+<p>A new identity ({{ .Provider }}) has been linked to your account.</p>
+```
+
+### `FactorType`
+
+Contains the type of the newly enrolled/unenrolled MFA factor. This is only available in the `mfa_factor_enrolled_notification` and `mfa_factor_unenrolled_notification` email templates.
+
+**Usage**
+
+```html
+<p>A new factor ({{ .FactorType }}) has been enrolled for your account.</p>
+```
+
## Deploying email templates
These settings are for local development. To apply the changes locally, stop and restart the Supabase containers:
diff --git a/apps/docs/spec/cli_v1_config.yaml b/apps/docs/spec/cli_v1_config.yaml
index 803059e6e56..685ca324427 100644
--- a/apps/docs/spec/cli_v1_config.yaml
+++ b/apps/docs/spec/cli_v1_config.yaml
@@ -984,6 +984,66 @@ parameters:
- name: 'Auth Server configuration'
link: 'https://supabase.com/docs/reference/auth'
+ - id: 'auth.email.notification.type.enabled'
+ title: 'auth.email.notification.<type>.enabled'
+ tags: ['auth']
+ required: false
+ description: |
+ Determines whether or not to send email notifications for the given type.
+
+ The full list of email notification types are:
+
+ - `password_changed`
+ - `email_changed`
+ - `phone_changed`
+ - `mfa_factor_enrolled`
+ - `mfa_factor_unenrolled`
+ - `identity_linked`
+ - `identity_unlinked`
+ links:
+ - name: 'Auth Server configuration'
+ link: 'https://supabase.com/docs/reference/auth'
+
+ - id: 'auth.email.notification.type.subject'
+ title: 'auth.email.notification.<type>.subject'
+ tags: ['auth']
+ required: false
+ description: |
+ The subject for the given email notification type.
+
+ The full list of email notification types are:
+
+ - `password_changed`
+ - `email_changed`
+ - `phone_changed`
+ - `mfa_factor_enrolled`
+ - `mfa_factor_unenrolled`
+ - `identity_linked`
+ - `identity_unlinked`
+ links:
+ - name: 'Auth Server configuration'
+ link: 'https://supabase.com/docs/reference/auth'
+
+ - id: 'auth.email.notification.type.content_path'
+ title: 'auth.email.notification.<type>.content_path'
+ tags: ['auth']
+ required: false
+ description: |
+ The relative path to the content template for the given email notification type.
+
+ The full list of email notification types are:
+
+ - `password_changed`
+ - `email_changed`
+ - `phone_changed`
+ - `mfa_factor_enrolled`
+ - `mfa_factor_unenrolled`
+ - `identity_linked`
+ - `identity_unlinked`
+ links:
+ - name: 'Auth Server configuration'
+ link: 'https://supabase.com/docs/reference/auth'
+
- id: 'auth.sms.enable_signup'
title: 'auth.sms.enable_signup'
tags: ['auth']