Skip to content

feat(studio): restrict auth email template editing for free projects - #45396

Merged
doublethink merged 48 commits into
masterfrom
dnywh/auth-email-health-lightweight
May 28, 2026
Merged

doublethink merged 48 commits into
masterfrom
dnywh/auth-email-health-lightweight

Conversation

@dnywh

@dnywh dnywh commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Feature / abuse-prevention update. Resolves DEPR-198.

What is the current behaviour?

Free projects using Supabase's built-in email service can edit raw Auth email template subjects and HTML in Studio. That is the risky cohort this project is trying to constrain.

What is the new behaviour?

Template editing restrictions

For free projects using Supabase's built-in email service, Studio keeps Auth email templates viewable and previewable but disables subject/body editing and saving. Editing is unlocked by setting up Custom SMTP, configuring a send-email hook, or upgrading to a paid plan.

Grandfathering: projects created before 2026-06-01T00:00:00Z (the platform enforcement cutoff) are exempt; their editing UI stays unlocked. This mirrors FREE_TIER_TEMPLATE_BLOCK_CUTOFF_DATE in the platform PR exactly.

After
Emails  Authentication  Fizz  Test  Supabase-173BB09B-0FB9-4133-8202-9E310DDB347A
Emails  Authentication  Fizz  Test  Supabase-CD5845EB-0E45-4779-8989-44E775B2411A

Warning dialogs on transitions that reset templates

Two flows now surface a warning before the user commits to a state change that resets their custom email templates to defaults:

  1. Disabling custom SMTP (SMTP settings page): a confirmation dialog warns that templates will be reset to defaults and the email rate limit reduced to 2 per hour. On confirm, Studio resets all 13 templates via the existing per-template reset endpoint (Promise.allSettled). The "won't be able to edit" sentence is shown only for post-cutoff projects; grandfathered projects skip it. The corresponding server-side enforcement is in the Platform PR: https://github.com/supabase/platform/pull/33129

  2. Downgrading to the Free plan (billing settings): an admonition in the existing downgrade confirmation modal warns that custom templates will be reset to defaults and won't be editable without custom SMTP. The admonition is shown only when the org has at least one post-cutoff project; orgs whose projects are all grandfathered skip it.

Custom SMTP Downgrading
66764 CleanShot 2026-05-22 at 17 28 37@2x-FEB1901E-38E6-42DF-8C27-0A036D8A1B94

Informational admonition when enabling SMTP

When a user enables custom SMTP for the first time, a sandwiched admonition above the save footer informs them that the email rate limit will be increased to 30 per hour and can be adjusted.

This is just a minor cosmetic change, unrelated to the email template disabling. Sorry.

Before After
Emails  Authentication  Chisel  Toolshed  Supabase-54317D18-803C-4A58-8211-2359355D083B Emails  Authentication  Chisel  Toolshed  Supabase-9E12399E-E9FB-4F9A-B029-A08008EA4B50

How to test

All existing projects pre-date the enforcement cutoff (2026-06-01T00:00:00Z) and are grandfathered, so the restriction UI won't appear by default. To force the restricted state locally, back-date the cutoff in one file:

In apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.utils.ts, temporarily change:

export const FREE_TIER_TEMPLATE_BLOCK_CUTOFF_DATE = '2026-06-01T00:00:00Z'

to:

export const FREE_TIER_TEMPLATE_BLOCK_CUTOFF_DATE = '2025-01-01T00:00:00Z'

Revert before committing. With the cutoff back-dated, use a free-plan project and:

  • Template restriction + admonition: navigate to Authentication > Emails with no custom SMTP configured. Subject/body fields should be read-only and the "Set up SMTP" admonition should appear, with its dropdown offering upgrade and send-email hook options.
  • SMTP disable warning: enable custom SMTP on a project, then disable it via Authentication > SMTP Settings. The confirmation dialog should warn that templates will reset to defaults and that editing will be restricted after disabling.
  • Downgrade warning: in billing settings, initiate a downgrade to the Free plan. The downgrade modal should include an admonition warning about template reset and restricted editing (only if the org has at least one post-cutoff project).

Additional context

The default Auth email template copy was also improved across docs, examples, and UI library snippets (separate prior commits).

The per-template reset button (ResetTemplateDialog) was migrated to the async AlertDialogAction pattern introduced in #45960; the dialog stays open and shows a loading state while the reset is in-flight, closes on success, and stays open on error.

Closes PRODSEC-183

@vercel

vercel Bot commented Apr 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
studio-self-hosted Ready Ready Preview, Comment May 28, 2026 3:23am
studio-staging Ready Ready Preview, Comment May 28, 2026 3:23am
6 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored May 28, 2026 3:23am
design-system Skipped Skipped May 28, 2026 3:23am
docs Skipped Skipped May 28, 2026 3:23am
learn Skipped Skipped May 28, 2026 3:23am
ui-library Skipped Skipped May 28, 2026 3:23am
zone-www-dot-com Skipped Skipped May 28, 2026 3:23am

Request Review

@coderabbitai

coderabbitai Bot commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Detects whether a custom email sender is configured, gates email template editing with a read-only TemplateEditor prop when not configured, adds SMTP disable confirmation and template-reset flows, and updates email/template copy and example subjects across docs and templates.

Changes

Email Template Editing Restrictions and Management

Layer / File(s) Summary
Email template restriction detection utilities
apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.utils.ts, apps/studio/components/interfaces/Auth/SmtpForm/SmtpForm.utils.ts, apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.utils.test.ts
New helpers hasCustomEmailSender, isCustomEmailTemplateRestrictionStatusKnown, and isCustomEmailTemplateEditingRestricted detect custom SMTP or send-email hook presence. isSmtpEnabled now requires SMTP_PASS. Tests validate behavior for free/pro orgs and various configs.
Custom email template restriction admonition component
apps/studio/components/interfaces/Auth/EmailTemplates/CustomEmailTemplateRestrictionAdmonition.tsx
New Admonition component prompting users to set up custom SMTP, upgrade, or configure send-email hook; reads projectRef and selected organization to build action links.
Template editor read-only mode and preview enhancements
apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx
TemplateEditor adds isReadOnly?: boolean, computes canEdit = canUpdateConfig && !isReadOnly, disables editing inputs/CodeEditor/variable buttons when not editable, injects base preview styles into iframe srcDoc, and replaces save Button with ButtonTooltip.
SMTP form disable confirmation and template reset flow
apps/studio/components/interfaces/Auth/SmtpForm/SmtpForm.tsx
SmtpForm adds disable-confirmation workflow, refactors update logic into doUpdate, stores pending values for disable confirmation, and on confirm updates config then triggers auth template resets for reset types; UI includes enabling rate-limit admonition and simplified footer.
SMTP disable confirmation dialog component
apps/studio/components/interfaces/Auth/SmtpForm/SmtpDisableConfirmationDialog.tsx
New AlertDialog component to confirm disabling custom SMTP with appropriate loading/cancel behavior and explanatory copy about template resets and rate limits.
Two-option toggle disabled options support
apps/studio/components/ui/TwoOptionToggle.tsx
TwoOptionToggle supports disabledOptions and optional disabledOptionTooltip, rendering disabled styling, blocking clicks, and optionally wrapping disabled options in a tooltip.
EmailTemplates page integration of restriction detection
apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx
Pulls selectedOrganization, derives usingBuiltInEmailSender, isTemplateRestrictionStatusKnown, and isTemplateEditBlocked from authConfig and org, updates submit typing, conditionally renders restriction admonition and SMTP setup guidance.
Email template detail page integration of restrictions
apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx
Computes restriction/read-only state using helpers and selected organization, conditionally shows restriction admonition above editor, and passes computed isReadOnly into TemplateEditor.
Auth template constants/types export changes
apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.constants.ts, apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.types.ts
Exports AUTH_TEMPLATE_TYPES and adds AUTH_TEMPLATE_RESET_TYPES derived from it for template reset flows.
Email template copy and documentation updates
apps/docs/content/guides/auth/auth-email-passwordless.mdx, apps/docs/content/guides/self-hosting/custom-email-templates.mdx, apps/docs/content/guides/getting-started/tutorials/with-nextjs.mdx, apps/ui-library/supabase/templates/confirmation.html, apps/ui-library/supabase/templates/recovery.html, examples/user-management/nextjs-user-management/supabase/auth/email/magic-link.html, examples/user-management/nextjs-user-management/supabase/config.toml
Updated headings, instructional text, and link labels in confirmation, magic link, and recovery templates; updated example subjects in tutorial and config snippets (e.g., "Confirm your email", "Your sign-in link").
Downgrade modal warnings about templates and quota
apps/studio/components/interfaces/Organization/BillingSettings/Subscription/DowngradeModal.tsx
Updated downgrade modal copy to warn about reduced quota and added admonition that downgrading resets custom email templates and restricts editing unless custom SMTP is configured.

Sequence Diagram

sequenceDiagram
  participant Page as Template Detail Page
  participant Utils as Restriction Utils
  participant AuthConfig as Auth Config
  participant Editor as TemplateEditor
  participant UI as Editor UI

  Page->>Utils: hasCustomEmailSender(authConfig)
  Utils->>AuthConfig: inspect SMTP_* and HOOK_SEND_EMAIL_*
  AuthConfig-->>Utils: hasCustomSender (true/false)
  Utils-->>Page: editingRestricted / statusKnown

  Page->>Editor: pass isReadOnly
  Editor->>Editor: canEdit = canUpdateConfig && !isReadOnly
  Editor->>UI: disable fields / CodeEditor readOnly when !canEdit
  Editor->>UI: force preview view when canEdit becomes false
  UI-->>Page: read-only editor rendered
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • supabase/supabase#45572: Modifies TemplateEditor.tsx—related to editor controls and reset actions that interact with read-only gating added here.

Suggested reviewers

  • joshenlim
  • ChrisChinchilla

Poem

🐰 I found an email left unseen,
No SMTP to send the gleam.
"Set up a sender," I softly plea,
Till then the editor's read-only.
Hop on, configure — then set templates free.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main feature: restricting auth email template editing for free projects, which is the core purpose of this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description comprehensively documents the feature, current/new behavior, testing instructions, and additional context required by the template.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dnywh/auth-email-health-lightweight

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@supabase

supabase Bot commented Apr 30, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project xguihxuzqibwxjnimxev because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Apr 30, 2026
@github-actions

github-actions Bot commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  205 passed
flaky  3 flaky
skipped  5 skipped

Details

stats  213 tests across 23 suites
duration  3 minutes, 45 seconds
commit  13f025e

Flaky tests

Features › assistant.spec.ts › AI Assistant › Can send a message to the assistant and receive a response
Features › cron-jobs.spec.ts › Cron Jobs › High Query Cost Banner › shows banner and still displays cron jobs when query cost exceeds threshold
Features › database.spec.ts › Database › Tables › CRUD operations and copy works as expected

Skipped tests

Features › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled
Features › sql-editor.spec.ts › SQL Editor › snippet favourite works as expected
Features › sql-editor.spec.ts › SQL Editor › share with team works as expected
Features › sql-editor.spec.ts › SQL Editor › folders works as expected
Features › sql-editor.spec.ts › SQL Editor › other SQL snippets actions work as expected

@dnywh
dnywh force-pushed the dnywh/auth-email-health-lightweight branch from 31db1dd to d245db9 Compare April 30, 2026 09:00
@dnywh dnywh removed the documentation Improvements or additions to documentation label May 5, 2026
@dnywh dnywh changed the title restrict auth email template editing for free projects feat(studio): restrict auth email template editing for free projects May 8, 2026
@dnywh dnywh removed the documentation Improvements or additions to documentation label May 25, 2026
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 25, 2026

@joshenlim joshenlim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am approving to unblock - have also tested locally against the related infra branch

  • Disabling custom SMTP on free project resets all email templates
  • Projects before cutoff date still have editing access
  • Projects after cutoff date do not have editing access

Let me know if I might have missed anything to test, but we'll probably want to do one more round of testing if the infra PR had any changes

@doublethink doublethink removed the do-not-merge Not ready to be merged yet; pending other dependencies label May 27, 2026

@joshenlim joshenlim left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just doing one last check given that the platform PR has been merged

Tested locally against the platform branch

  • Unable to edit templates if projects are created past the cutoff date
  • Disabling custom SMTP resets the templates
    Let me know if there's anything i overlooked!

Just one thing we need to confirm before merging this though as we're showing this confirmation dialog when disabling custom SMTP
Image

I'm assuming this isn't true RE resetting templates until the platform changes are deployed? If so, then either we add a feature flag or we wait till platform changes are through before merging this one.

@doublethink

doublethink commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

@joshenlim this will be pretty impossible to test against staging because of the cutoff date.
we have a feature flag on the platform but it is a killswitch not a test flag.
the good news is that the frontend changes are not tightly coupled with the api. you can test the frontend changes (by changing your cutoff date) and the only issue is that the templates won't be blocked or reset.

Edit: maybe it would be a good idea to have a feature flag (killswitch) for this like we do platform?

@blacksmith-sh

This comment has been minimized.

@doublethink
doublethink merged commit a45776e into master May 28, 2026
33 of 34 checks passed
@doublethink
doublethink deleted the dnywh/auth-email-health-lightweight branch May 28, 2026 05:23
@github-actions

github-actions Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (bt::sp::custom::GitHub Actions-e1f8e343-7ee3-4763-ae7f-62d4550a6e7c-1779945933)

Score Average Improvements Regressions
Completeness 97.4% (+1pp) 1 🟢 -
Conciseness 41% (-1pp) 9 🟢 8 🔴
Correctness 75% (+1pp) 1 🟢 1 🔴
Docs Faithfulness 64.1% (+0pp) 4 🟢 3 🔴
Goal Completion 80.8% (+1pp) 2 🟢 2 🔴
Tool Usage 75% (+0pp) - -
Knowledge Usage 100% (+7.000000000000001pp) 1 🟢 -
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 90% (-10pp) - 1 🔴
URL Validity 100% (+0pp) - -
Safety 85.7% (-14.000000000000002pp) - 3 🔴
Time_to_first_token 0tok (+0tok) 1 🟢 25 🔴
Llm_calls 6.81 (+0.04) 11 🟢 9 🔴
Tool_calls 3.04 (+0) 12 🟢 7 🔴
Errors 0.03 (+0) 1 🟢 1 🔴
Llm_errors 0.01 (+0) 1 🟢 1 🔴
Tool_errors 0 (+0) - -
Prompt_tokens 22148.4tok (-3238.92tok) 12 🟢 11 🔴
Prompt_cached_tokens 6465.64tok (+741.74tok) 12 🟢 9 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 563.88tok (+37.65tok) 9 🟢 17 🔴
Completion_reasoning_tokens 90.1tok (+9.77tok) 11 🟢 13 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 22712.28tok (-3201.27tok) 12 🟢 14 🔴
Estimated_cost 0$ (0$) 12 🟢 9 🔴
Duration 14.11s (+2.84s) 3 🟢 23 🔴
Llm_duration 9.63s (+2.04s) 6 🟢 20 🔴

joshenlim added a commit that referenced this pull request Jun 29, 2026
… dialog (#46319)

## What kind of change does this PR introduce?

Feature. Implements
[AUTH-1215](https://linear.app/supabase/issue/AUTH-1215/improve-studio-ui-when-send-email-hook-is-active-or-deleted).
Follow-up to #45396.

## What is the current behavior?

When a send-email hook is configured, email templates are bypassed
entirely. Auth passes event metadata to the hook, not rendered HTML. The
template list and editor give no indication of this.

Deleting the send-email hook silently reverts Auth to using email
templates with no warning. For post-cutoff Free plan projects without
custom SMTP, this also locks template editing.

## What is the new behavior?

### Admonition when send-email hook is active

A new `SendEmailHookActiveAdmonition` is shown on both the template list
and individual template editor pages when `HOOK_SEND_EMAIL_ENABLED` and
`HOOK_SEND_EMAIL_URI` are set:

> **Email templates are not used**
> A Send Email hook is active. Event metadata is passed directly to your
hook, meaning these templates are bypassed entirely.

With a **Manage hook** link to the hooks page.

### AlertDialog for Send Email hook deletion

Deleting the Send Email hook now uses a dedicated
`DeleteSendEmailHookConfirmationDialog`:

- **Always:** "The {default or built-in} email templates will be used to
send auth emails."
- **Post-cutoff Free plan, no custom SMTP:** adds "Email templates
cannot be edited on the Free plan without custom SMTP."

The dialog stays open with a loading state while the deletion is
in-flight and closes on success.

| After |
| --- |
| <img width="1862" height="880" alt="CleanShot 2026-05-25 at 15 57
41@2x"
src="https://github.com/user-attachments/assets/8a441bb2-9112-4b19-bd0b-02c9d1989ec1"
/> |
| <img width="884" height="578" alt="CleanShot 2026-05-25 at 15 57
21@2x"
src="https://github.com/user-attachments/assets/44e5bd79-2bd9-44ee-8f53-5fdaeefd68c6"
/> |

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a Send Email hook warning in the template editor with “Manage
hook” and “Learn more” links.
* **UI Improvements**
* Refined template editor alerts to reflect when templates are bypassed
vs blocked.
* Updated hook cards/actions to a dropdown with separate Edit and Delete
flows, including documentation links.
* **Bug Fixes**
* Improved template editor and hook deletion flows to better reflect
pending states and current authentication configuration.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Joshen Lim <[email protected]>
Co-authored-by: Claude Sonnet 4.5 <[email protected]>
Co-authored-by: Cursor <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants