Skip to content

feat(studio): add auth email template reset flow - #45572

Merged
dnywh merged 16 commits into
masterfrom
dnywh/auth-879-reset-email-template-defaults
May 18, 2026
Merged

dnywh merged 16 commits into
masterfrom
dnywh/auth-879-reset-email-template-defaults

Conversation

@dnywh

@dnywh dnywh commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Feature. Resolves AUTH-879.

What is the current behavior?

Studio does not provide a way to reset an Auth email template back to the default subject and body once it has been customised.

What is the new behavior?

Studio shows a Reset template action when Platform reports that the selected Auth email template subject or body has been customised. The action opens a confirmation dialog, calls the dedicated Platform reset endpoint, and refreshes the editor with the default subject and body returned by the API.

The Auth config save/reset mutations now run their user-facing success handling before refreshing Auth lint data, so the success toast and local editor cleanup are not delayed by lint refetches.

Additional context

Depends on supabase/platform#32417.

Summary by CodeRabbit

  • New Features

    • Reset email templates to defaults via a confirmation dialog; button appears when custom content is detected and respects update permissions.
    • Typed email-template definitions and improved template variable display and descriptions.
  • Tests

    • Added tests covering template reset visibility, confirmation flow, state updates, permission handling, and toast notifications.
  • Documentation

    • Example email template placeholders updated for internationalization and provider snippets.

Review Change Stack

@vercel

vercel Bot commented May 5, 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 18, 2026 4:22am
studio-staging Ready Ready Preview, Comment May 18, 2026 4:22am
6 Skipped Deployments
Project Deployment Actions Updated (UTC)
studio Ignored Ignored May 18, 2026 4:22am
design-system Skipped Skipped May 18, 2026 4:22am
docs Skipped Skipped May 18, 2026 4:22am
learn Skipped Skipped May 18, 2026 4:22am
ui-library Skipped Skipped May 18, 2026 4:22am
zone-www-dot-com Skipped Skipped May 18, 2026 4:22am

Request Review

@supabase

supabase Bot commented May 5, 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 ↗︎.

@coderabbitai

coderabbitai Bot commented May 5, 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
  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

This PR implements email template reset functionality across API types, domain/network layers, TemplateEditor UI, and tests. It adds a new POST /platform/auth/{ref}/templates/{template}/reset endpoint returning updated auth config, introduces typed template definitions with a new AuthTemplate interface, creates a reset mutation hook with cache updates, wires the UI with a confirmation dialog, reorganizes existing templates to the new schema, and provides comprehensive test coverage.

Changes

Email Template Reset Feature

Layer / File(s) Summary
API types and schema
packages/api-types/types/platform.d.ts
Adds POST /platform/auth/{ref}/templates/{template}/reset path and TemplateController_resetTemplate operation; extends GoTrueConfigResponse with MAILER_SUBJECTS_CUSTOM_CONTENTS and MAILER_TEMPLATES_CUSTOM_CONTENTS boolean flag objects.
Template type definitions
apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.types.ts
Introduces KebabCase string transformer type, AUTH_TEMPLATE_TYPES tuple, derives AuthTemplateType and AuthTemplateResetType, and defines AuthTemplate interface with id, properties map, Zod validation schema, and email template type discriminator.
Template utility functions
apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.utils.ts
Adds getAuthTemplateType() function to convert AuthTemplateType values to lowercase kebab-case strings.
Reset mutation hook and network
apps/studio/data/auth/auth-template-reset-mutation.ts
Implements resetAuthTemplate async function posting to reset endpoint; exports useAuthTemplateResetMutation hook that updates auth-config cache without refetch, invalidates lint query with active refetch (fire-and-forget), and handles errors via toast.
Auth-config update cache behavior
apps/studio/data/auth/auth-config-update-mutation.ts
Adjusts useAuthConfigUpdateMutation.onSuccess to write auth config to cache, invalidate auth-config without refetch, await user onSuccess callback, then run lint invalidation/refetch as non-blocking chain.
Template schema type reorganization
apps/studio/components/interfaces/Auth/EmailTemplates/AuthTemplatesValidation.tsx
Converts all template constants from FormSchema to AuthTemplate type: authentication templates (CONFIRMATION through REAUTHENTICATION), notification templates (PASSWORD_CHANGED through IDENTITY_LINKED, MFA_FACTOR_ENROLLED, MFA_FACTOR_UNENROLLED). Updates notification descriptions for identity linked, MFA factor enrolled, and MFA factor unenrolled.
TemplateEditor UI and wiring
apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.tsx
Adds AlertDialog components, updates props to accept AuthTemplate, derives typed content/subject slugs and template type, adds isResettingTemplate state, memoizes form-value builder, computes hasCustomTemplate, implements resetTemplateToDefault() handler, updates effect to reset form/body from config changes, and adds conditional Reset dialog in footer with updated button disabled/loading logic.
Import path updates
apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx, apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx
Updates TEMPLATES_SCHEMAS import to local ./AuthTemplatesValidation module; updates [templateId] page imports to use named imports for DefaultLayout and NoPermission.
Reset flow test suite
apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.test.tsx
New Vitest suite with hoisted mocks for hooks, components, and APIs. Includes helper functions for test setup and nine test cases covering reset-button visibility (custom content flags), hiding on unsaved edits, confirmation dialog with mutation payload validation, absence of auth-update call, editor state sync after reset, and permission-based disabling.

Sequence Diagram

sequenceDiagram
  participant User
  participant Editor as TemplateEditor
  participant Dialog as AlertDialog
  participant Mutation as ResetMutation
  participant API as API Endpoint
  participant Cache as React Query Cache
  participant Toast as Sonner Toast
  User->>Editor: view template with custom content
  Editor->>Editor: show Reset button
  User->>Editor: click reset button
  Editor->>Dialog: open confirmation dialog
  User->>Dialog: confirm reset action
  Dialog->>Editor: on confirm callback
  Editor->>Mutation: mutate with projectRef and template
  Mutation->>API: POST /platform/auth/{ref}/templates/{template}/reset
  API-->>Mutation: GoTrueConfigResponse with reset config
  Mutation->>Cache: setQueryData for authConfig
  Mutation->>Cache: invalidate authConfig no refetch
  Mutation->>Cache: invalidate lint query async
  Mutation->>Editor: on success with reset response
  Editor->>Editor: reset form values from response
  Editor->>Editor: update editor body from response
  Editor->>Editor: clear unsaved changes state
  Editor->>Toast: success notification
  Toast-->>User: show success message
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit hops through templates bright,
Resetting to defaults with a single click delight!
Forms reset, caches clear with finesse,
Dialogs confirm without any stress! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main feature added: a reset flow for auth email templates.
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 PR description addresses all major template sections with clear explanations of current behavior, new behavior, and additional context.

✏️ 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-879-reset-email-template-defaults

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.

@github-actions

github-actions Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  207 passed
skipped  5 skipped

Details

stats  212 tests across 23 suites
duration  5 minutes, 20 seconds
commit  5d37918

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 added dnc DO NOT CLOSE do-not-merge Not ready to be merged yet; pending other dependencies and removed dnc DO NOT CLOSE labels May 5, 2026
@dnywh
dnywh marked this pull request as ready for review May 5, 2026 05:52
@dnywh
dnywh requested a review from a team as a code owner May 5, 2026 05:52
@dnywh dnywh changed the title Add Auth email template reset flow in Studio feat(studio): add auth email template reset flow May 8, 2026
@dnywh dnywh removed the do-not-merge Not ready to be merged yet; pending other dependencies label May 8, 2026
@joshenlim

Copy link
Copy Markdown
Member

@dnywh btw this would be another example for async handling in AlertDialog haha if you recall the thread we had before - if we should bake that behaviour into the UI component

@joshenlim

Copy link
Copy Markdown
Member

@dnywh alrighty - code changes wise should be good now, just needs e2e testing when the BE changes are through 🙏 🙂

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 11, 2026
dnywh and others added 2 commits May 11, 2026 19:03
## Context

Reworks the template variables section of an email template a little
- Add a section header with docs button
<img width="1112" height="133" alt="image"
src="https://github.com/user-attachments/assets/34f27c81-a7d7-430c-b23b-f95bf6572c8c"
/>
- Refactor `AuthTemplatesValidation` to remove unnecessary description
parsing logic in `TemplateEditor`
- Update tooltip content to match
[docs](https://supabase.com/docs/guides/local-development/customizing-email-templates#template-variables)
  - e.g `SiteURL`: Add inline link for configuration
<img width="480" height="96" alt="image"
src="https://github.com/user-attachments/assets/731312bd-e46b-4cd2-81e9-85a67c9e318e"
/>
- e.g `Token`: Mention that its swappable with `ConfirmationURL` if both
parameters are available for use in the template (Counter example is the
reauthentication template which there's only `Token` variable available)
<img width="462" height="93" alt="image"
src="https://github.com/user-attachments/assets/63017f28-3d84-4840-8217-ba113646b63b"
/>
<img width="262" height="122" alt="image"
src="https://github.com/user-attachments/assets/e3450eb8-7ff5-4eec-920f-77bb5fd4f367"
/>

---------

Co-authored-by: Danny White <[email protected]>
@dnywh

dnywh commented May 15, 2026

Copy link
Copy Markdown
Contributor Author

@dnywh btw this would be another example for async handling in AlertDialog haha if you recall the thread we had before - if we should bake that behaviour into the UI component

Roger that. Handling in #45960

@ChrisChinchilla ChrisChinchilla left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From a docs perspective ✅

@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.

Verified changes on preview!

@dnywh
dnywh merged commit f45a608 into master May 18, 2026
25 of 26 checks passed
@dnywh
dnywh deleted the dnywh/auth-879-reset-email-template-defaults branch May 18, 2026 04:33
@github-actions

github-actions Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1779078914)

Score Average Improvements Regressions
Completeness 94.7% (-3pp) 1 🟢 3 🔴
Conciseness 39.3% (-1pp) 6 🟢 6 🔴
Goal Completion 76% (-5pp) 4 🟢 8 🔴
Knowledge Usage 96.7% (+0pp) - -
Tool Usage 73.3% (+0pp) 1 🟢 1 🔴
Docs Faithfulness 68.1% (+1pp) 2 🟢 2 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 98% (+11pp) 1 🟢 -
Correctness 70.8% (-3pp) - 2 🔴
Safety 100% (+5pp) 1 🟢 -
URL Validity 100% - -
Time_to_first_token 0.01tok (0tok) 17 🟢 8 🔴
Llm_calls 11.68 (+0.47) 16 🟢 6 🔴
Tool_calls 3.08 (+0.12) 10 🟢 10 🔴
Errors 0 (-0.04) 1 🟢 -
Llm_errors 0 (-0.03) 1 🟢 -
Tool_errors 0 (+0) - -
Prompt_tokens 19906.99tok (-226.91tok) 10 🟢 11 🔴
Prompt_cached_tokens 7017.81tok (+471.04tok) 12 🟢 8 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 565.57tok (+12.04tok) 14 🟢 11 🔴
Completion_reasoning_tokens 110.19tok (+18.96tok) 10 🟢 12 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 20472.56tok (-214.87tok) 13 🟢 12 🔴
Estimated_cost 0$ (0$) 10 🟢 13 🔴
Duration 18.69s (+1.3s) 9 🟢 16 🔴
Llm_duration 10.63s (+1.55s) 6 🟢 19 🔴

dnywh added a commit that referenced this pull request May 22, 2026
## What kind of change does this PR introduce?

Feature, bug fix, and docs update. Addresses the AlertDialog async
action behaviour discussed in Slack and follow-up PR feedback.

## What is the current behavior?

`AlertDialogAction` delegates directly to Radix, so confirm actions
close the dialog immediately on click. Async mutation flows have to use
`asChild` with `event.preventDefault()` and a custom loading button to
keep the dialog open while work is in flight.

## What is the new behavior?

- `AlertDialogAction` now accepts async handlers and a controlled
`loading` prop. Promise-returning actions keep the dialog open, show the
existing Button loading state, disable cancel/dismissal while pending,
close on success, and stay open on rejection.
- Existing workaround usages in Studio have been migrated to the direct
action API (see 'To test' callsite list below)
- design-system docs now include async action examples and
`AlertDialogBody` guidance for inline feedback


https://github.com/user-attachments/assets/1af66410-e9f9-4231-9c6d-fe650bd717a4


## Additional context

- [ ] Once #45572 is rebased onto this change, `ResetTemplateDialog`
should use `AlertDialogAction loading={isResettingTemplate}` with a
promise-returning reset handler instead of a plain loading `Button` in
`AlertDialogFooter`.

## To test

- [x] On Studio API Keys settings, use a project with no publishable or
secret API keys, click the “Create API keys” banner action, and confirm
the Alert Dialog stays open with loading until the default publishable
and secret keys are created.
- [x] Delete a JIT database access rule and confirm the Alert Dialog
stays open with loading until deletion succeeds, and stays open with
inline feedback if it fails.
- [x] With temporary access disabled and existing rules configured,
enable temporary access and confirm the “This will activate existing
rules” Alert Dialog stays open with loading until the configuration
update succeeds, and stays open with inline feedback if it fails.
- [x] Disable external replication and confirm the Alert Dialog stays
open with loading until the mutation succeeds.
- [x] Enable Index Advisor and confirm the Alert Dialog stays open with
loading until the mutation succeeds, and stays open with inline feedback
if it fails.


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

* **New Features**
* Alert dialogs support async actions with built-in loading, dismissal
blocking while pending, and preserved dialog on error.
* Two interactive examples demonstrating async success and error flows.

* **Improvements**
* Dialogs now surface inline error messages and consistent
loading/confirm behavior across flows (create keys, replication, JIT DB
access, index advisor).
  * Minor UI refinements for action controls.

* **Documentation**
* Docs updated with async-action guidance and inline-error
recommendations.

* **Tests**
  * New test suite validating async dialog behaviors.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45960)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Gildas Garcia <[email protected]>
joshenlim pushed a commit that referenced this pull request Jul 8, 2026
…#47705)

## What kind of change does this PR introduce?

Bug fix / refactor. Resolves DEPR-573.

## What is the current behavior?

`ResetTemplateDialog` (added in #45572) confirms the Auth email template
reset using the old `AlertDialog` workaround: an `AlertDialogAction`
with `asChild` + `event.preventDefault()` and a manual loading `Button`,
driven by `mutate` plus inline callbacks. Reset failures are only
reported via a toast from the mutation's default `onError`, so the error
disappears from the dialog context.

This predates #45960, which added first-class async handling to
`AlertDialogAction` (promise-returning handlers, controlled `loading`,
and `AlertDialogBody` for inline feedback). #45960 explicitly flagged
`ResetTemplateDialog` as needing this follow-up migration.

## What is the new behavior?

`ResetTemplateDialog` now uses the async `AlertDialogAction` pattern:

- The confirm handler uses `mutateAsync` and returns the reset promise,
so the dialog stays open with a loading state while the mutation is
pending and closes only after it succeeds.
- Reset failures surface inline via a destructive `Admonition` inside
`AlertDialogBody`, and the mutation's toast-only error path is
suppressed (`onError: () => {}`). The inline error clears when the
dialog closes.
- `Cancel` is disabled while the reset is in flight.
- The `asChild` + `preventDefault()` workaround and the manual loading
`Button` are removed; `loading={isResetting}` is retained for
parent-controlled loading.

This matches the established usage in `DisablePipelinesDialog` /
`JitDbAccessDeleteDialog` and the design-system
`alert-dialog-async-error` example.

## To test

- [ ] Customise an Auth email template, click **Reset template**,
confirm the dialog shows loading until the reset succeeds and then
closes with the editor refreshed to the default subject/body.
- [ ] In DevTools → Network, block `*/templates/*/reset`, click
**Reset**, and confirm the dialog stays open with an inline destructive
admonition and no toast.

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

* **Bug Fixes**
* Improved email template reset error handling by showing reset failures
inline in the confirmation dialog (with a destructive alert message).
* The dialog remains open on reset failure so users can review the error
and retry.
* “Cancel” is disabled while resetting; success behavior and existing
success toast behavior remain unchanged.
* **Tests**
* Updated reset mutation mock to use async behavior and added coverage
for reset failure UI/error handling (including that error toasts are not
triggered).
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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