Skip to content

feat: surface send-email hook status in template UI and hook deletion dialog - #46319

Merged
joshenlim merged 43 commits into
masterfrom
dnywh/auth-1215-send-email-hook-ui
Jun 29, 2026
Merged

joshenlim merged 43 commits into
masterfrom
dnywh/auth-1215-send-email-hook-ui

Conversation

@dnywh

@dnywh dnywh commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Feature. Implements AUTH-1215. 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
CleanShot 2026-05-25 at 15 57 41@2x
CleanShot 2026-05-25 at 15 57 21@2x

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.

dnywh and others added 30 commits April 30, 2026 19:00
…ogAction async pattern

Uses the async AlertDialogAction from #45960 so dialogs stay open during
in-flight mutations and close on success. Removes manual isLoading tracking.

- SmtpDisableConfirmationDialog: AlertDialogAction with async onClick; dialog
  stays open while SMTP config update + all template resets complete, closes
  on success, stays open if SMTP update fails
- SmtpForm: handleConfirmDisable returns Promise; resolves after resets settle,
  rejects if SMTP update fails so dialog keeps the user in context
- ResetTemplateDialog: same migration per #45960 TODO; async mutateAsync handler,
  AlertDialogAction replaces manual Button/loading pattern

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
The component was migrated to the AlertDialogAction async pattern
(mutateAsync instead of mutate), but the test mock still provided
the old mutate callback interface. Update mock to return mutateAsync
with mockResolvedValue and remove the now-absent callbacks argument
from the call assertion.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@github-actions

github-actions Bot commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

🎭 Playwright Test Results

passed  221 passed
skipped  5 skipped

Details

stats  226 tests across 25 suites
duration  3 minutes, 1 second
commit  9803d72

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 and others added 3 commits May 25, 2026 15:46
Replace admonition-inside-ConfirmationModal with a dedicated
DeleteSendEmailHookConfirmationDialog following the AlertDialog pattern
(matching SmtpDisableConfirmationDialog). Removes em dashes, uses
"Free plan" capitalisation, and drops third-person "Auth will revert"
phrasing in favour of "The default email templates will be used".

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Base automatically changed from dnywh/auth-email-health-lightweight to master May 28, 2026 05:23
Resolve merge conflicts while preserving send-email hook UI changes
and adopting master refactors (dayjs cutoff helper, Dialog migration,
DiscardChangesConfirmationDialog, execute-sql-mutation import).

Co-authored-by: Cursor <[email protected]>
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jun 26, 2026

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx (1)

295-304: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Same dual-admonition overlap as in EmailTemplates.tsx.

When isTemplateEditBlocked and hasSendEmailHook are both true, the SMTP-restriction notice and the "templates bypassed" notice render together, which is contradictory. Consider the same gating suggested in EmailTemplates.tsx.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/pages/project/`[ref]/auth/templates/[templateId].tsx around lines
295 - 304, The template settings view currently renders both
CustomEmailTemplateRestrictionAdmonition and SendEmailHookActiveAdmonition
together when isTemplateEditBlocked and hasSendEmailHook are both true, creating
contradictory messaging. Update the conditional rendering in the [templateId]
page to apply the same mutual-exclusion gating used in EmailTemplates.tsx so
only the appropriate admonition shows at a time. Use the existing
isTemplateEditBlocked and hasSendEmailHook checks to prevent the overlap while
preserving the current layout.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx`:
- Around line 142-156: The two admonitions in EmailTemplates can render together
even though `hasSendEmailHook` makes template editing irrelevant, so update the
conditional rendering in `EmailTemplates` to suppress
`CustomEmailTemplateRestrictionAdmonition` whenever `hasSendEmailHook` is true.
Keep `SendEmailHookActiveAdmonition` as the higher-priority notice and adjust
the `isTemplateEditBlocked` branch to depend on both flags so the messages are
never contradictory.

---

Outside diff comments:
In `@apps/studio/pages/project/`[ref]/auth/templates/[templateId].tsx:
- Around line 295-304: The template settings view currently renders both
CustomEmailTemplateRestrictionAdmonition and SendEmailHookActiveAdmonition
together when isTemplateEditBlocked and hasSendEmailHook are both true, creating
contradictory messaging. Update the conditional rendering in the [templateId]
page to apply the same mutual-exclusion gating used in EmailTemplates.tsx so
only the appropriate admonition shows at a time. Use the existing
isTemplateEditBlocked and hasSendEmailHook checks to prevent the overlap while
preserving the current layout.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 87c29497-fd63-4967-bb61-0db921b71f82

📥 Commits

Reviewing files that changed from the base of the PR and between a074b62 and b1240de.

📒 Files selected for processing (6)
  • apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx
  • apps/studio/components/interfaces/Auth/EmailTemplates/SendEmailHookActiveAdmonition.tsx
  • apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.test.tsx
  • apps/studio/components/interfaces/Auth/Hooks/DeleteSendEmailHookConfirmationDialog.tsx
  • apps/studio/components/interfaces/Auth/Hooks/HooksListing.tsx
  • apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx

Copilot AI 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.

Pull request overview

Adds clearer Studio UX around the “Send Email” Auth Hook so users understand when templates are bypassed, and makes hook deletion safer by warning about the impact on template usage/editability.

Changes:

  • Surfaces a “Send Email hook is active” admonition on both the email template list and template editor pages.
  • Introduces a dedicated AlertDialog flow for deleting the Send Email hook, including an extra warning for post-cutoff Free plan projects without custom SMTP.
  • Updates hook deletion wiring to clear the Send Email hook’s stored config keys and adjusts a TemplateEditor test mock to match the mutation shape.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
apps/studio/pages/project/[ref]/auth/templates/[templateId].tsx Shows the “Send Email hook active” admonition in the template editor UI when the hook is configured.
apps/studio/components/interfaces/Auth/Hooks/HooksListing.tsx Routes Send Email hook deletions through the new confirmation dialog and computes whether deletion will lock template editing.
apps/studio/components/interfaces/Auth/Hooks/DeleteSendEmailHookConfirmationDialog.tsx New dedicated confirmation dialog component for deleting the Send Email hook.
apps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.test.tsx Updates the reset mutation mock to include isPending.
apps/studio/components/interfaces/Auth/EmailTemplates/SendEmailHookActiveAdmonition.tsx New admonition component explaining templates are bypassed when the Send Email hook is active.
apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsx Shows the admonition on the template list page and adjusts how multiple warnings/admonitions are displayed together.

Suppress the SMTP restriction admonition when a send-email hook is active,
fix invalid nested paragraph markup in the delete hook dialog, and correct
the delete handler return type for TypeScript.

Co-authored-by: Cursor <[email protected]>
@dnywh dnywh removed the documentation Improvements or additions to documentation label Jun 27, 2026
const { mutate: updateAuthHooks, isPending: isDeletingAuthHook } = useAuthHooksUpdateMutation({
const {
mutate: updateAuthHooks,
mutateAsync: updateAuthHooksAsync,

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.

we could just use the original mutate one - otherwise mutateAsync requires error handling within a try catch block too

Comment on lines +102 to +113
const handleDeleteSendEmailHook = async (): Promise<void> => {
if (!selectedHookForDeletion) return
await updateAuthHooksAsync({
projectRef: projectRef!,
config: {
[selectedHookForDeletion.enabledKey]: false,
[selectedHookForDeletion.uriKey]: null,
[selectedHookForDeletion.secretsKey]: null,
},
})
}

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.

this also seems like repeated logic with the confirmation modal below - modal can use this method

Comment on lines 206 to 215
<DeleteSendEmailHookConfirmationDialog
open={selectedHookForDeletion?.id === 'send-email'}
onOpenChange={(open) => {
if (!open) setSelectedHookForDeletion(null)
}}
onConfirm={handleDeleteSendEmailHook}
willLockTemplates={willLockTemplatesOnSendEmailDelete}
/>

<ConfirmationModal

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.

thinking we could probably extract this into a generic DeleteHookConfirmationDialog and handle the logic there

@joshenlim

joshenlim commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

just making some UI nudges since we're looking at this UI (these were bothering me for a while now but just never got to it 😅 )

adjusting the form layout here as well to be more consistent with other parts of the UI
image

adjust the cards here to be more consistent with other parts of the UI too (more action button)
image
image

)}
{hasSendEmailHook && (
<div className="mb-4">
<SendEmailHookActiveAdmonition />

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.

fwiw - wondering if this callout should also exist in the create send email hook panel

to give users a heads up that creating an email hook will no longer use the auth email templates
otherwise it feels like users are learning about this behaviour retroactively

willLockTemplates = false,
}: DeleteSendEmailHookConfirmationDialogProps) => {
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>

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.

needs to handle async action - otherwise dialog closes before success

title="Email templates are not used"
description={
<>
A Send Email hook is active. Email data is sent to your endpoint instead of using these

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.

"to your endpoint" sounds a little inaccurate - e.g if my hook uses a postgres function isntead

maybe a generic "sent to your hook" might be better?

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx (2)

183-197: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

Include schema changes in the revoke check.

If a hook moves from public.fn to private.fn, this branch skips getRevokePermissionStatements() because the function name is unchanged. That leaves supabase_auth_admin access on the old target. Compare both schema and function name before deciding there is nothing to revoke.

Suggested fix
-    if (hook.method.type === 'postgres') {
-      if (
-        hook.method.schema !== '' &&
-        hook.method.functionName !== '' &&
-        hook.method.functionName !== postgresValues.functionName
-      ) {
+    if (hook.method.type === 'postgres') {
+      if (
+        hook.method.schema !== '' &&
+        hook.method.functionName !== '' &&
+        (hook.method.schema !== postgresValues.schema ||
+          hook.method.functionName !== postgresValues.functionName)
+      ) {
         permissionChanges = getRevokePermissionStatements(
           hook.method.schema,
           hook.method.functionName
         )
       }
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx` around
lines 183 - 197, The revoke-permission logic in CreateHookSheet is only checking
functionName, so moving a hook between schemas can skip
getRevokePermissionStatements and leave old access behind. Update the comparison
in the permissionChanges branch to consider both hook.method.schema and
hook.method.functionName against postgresValues.schema and
postgresValues.functionName, and only skip revocation when both schema and
function are unchanged.

526-537: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Prevent “Generate secret” from submitting the form.

This button sits inside the form and has no explicit type, so clicking it will also trigger form submission. Users can accidentally create/update the hook while trying to generate a secret.

Suggested fix
                             <Button
+                              type="button"
                               variant="default"
                               className="rounded-l-none text-xs h-auto"
                               onClick={() => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx` around
lines 526 - 537, The “Generate secret” button inside CreateHookSheet currently
relies on the default button type and will submit the form when clicked. Update
the Button used in the CreateHookSheet form so it is explicitly non-submitting
(for example, by setting its type to a non-submit behavior) while keeping the
existing onClick logic that calls generateAuthHookSecret and form.setValue for
httpsValues.secret.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx`:
- Around line 211-214: The success toast in CreateHookSheet uses the wrong verb
for edit flows, since this sheet handles both create and update actions. Update
the onSuccess handler in CreateHookSheet and use the appropriate message based
on whether the hook is being created or edited, so the toast for update actions
does not say Successfully created; reference the updateAuthHooks mutation and
the toast.success call to locate the change.

In
`@apps/studio/components/interfaces/Auth/Hooks/DeleteHookConfirmationDialog.tsx`:
- Around line 44-59: The Postgres revoke step in DeleteHookConfirmationDialog’s
updateAuthHooks onSuccess flow is being treated as part of the config mutation,
so failures from executeSql are not handled separately. Move the revoke/cleanup
handling around getRevokePermissionStatements and executeSql into the confirm
flow or add a dedicated try/catch there, so you can show a specific toast for
permission cleanup failure while still completing the auth config deletion. Keep
the success path calling toast.success and onDeleteSuccess, but make the
partial-success state explicit when hook.method.type === 'postgres'.

In `@apps/studio/components/interfaces/Auth/Hooks/HookCard.tsx`:
- Around line 130-133: The DropdownMenu trigger in HookCard is currently nesting
a button inside the trigger and leaving the icon-only control unlabeled. Update
the DropdownMenuTrigger usage to use the asChild pattern around the existing
Button, and add an aria-label to that Button so the trigger is a single
accessible control. Keep the change localized to DropdownMenuTrigger and Button
in HookCard.

---

Outside diff comments:
In `@apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx`:
- Around line 183-197: The revoke-permission logic in CreateHookSheet is only
checking functionName, so moving a hook between schemas can skip
getRevokePermissionStatements and leave old access behind. Update the comparison
in the permissionChanges branch to consider both hook.method.schema and
hook.method.functionName against postgresValues.schema and
postgresValues.functionName, and only skip revocation when both schema and
function are unchanged.
- Around line 526-537: The “Generate secret” button inside CreateHookSheet
currently relies on the default button type and will submit the form when
clicked. Update the Button used in the CreateHookSheet form so it is explicitly
non-submitting (for example, by setting its type to a non-submit behavior) while
keeping the existing onClick logic that calls generateAuthHookSecret and
form.setValue for httpsValues.secret.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 66439687-71f7-4086-a493-1c598c4eb6a1

📥 Commits

Reviewing files that changed from the base of the PR and between be81cda and 7c5b86d.

📒 Files selected for processing (5)
  • apps/studio/components/interfaces/Auth/EmailTemplates/SendEmailHookActiveAdmonition.tsx
  • apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx
  • apps/studio/components/interfaces/Auth/Hooks/DeleteHookConfirmationDialog.tsx
  • apps/studio/components/interfaces/Auth/Hooks/HookCard.tsx
  • apps/studio/components/interfaces/Auth/Hooks/HooksListing.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/studio/components/interfaces/Auth/EmailTemplates/SendEmailHookActiveAdmonition.tsx

@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 staging preview! I'm gonna go ahead to merge this one since the changes will be useful for users - although just lemme know if anything needs tweaking from the UI changes that i've made 🙏 🙏

@joshenlim
joshenlim merged commit 8192d97 into master Jun 29, 2026
33 checks passed
@joshenlim
joshenlim deleted the dnywh/auth-1215-send-email-hook-ui branch June 29, 2026 09:09
@github-actions

github-actions Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Braintrust eval report

Assistant (master-1782724278)

Score Average Improvements Regressions
Completeness 98.8% (+2pp) 2 🟢 -
Conciseness 41.8% (-5pp) 3 🟢 6 🔴
Docs Faithfulness 69% (+11pp) 9 🟢 -
Goal Completion 78.8% (+0pp) 7 🟢 5 🔴
Tool Usage 74.5% (+0pp) 1 🟢 1 🔴
Knowledge Usage 97.4% (-3pp) - 1 🔴
Correctness 69.5% (+1pp) 3 🟢 3 🔴
SQL Identifier Quoting 100% (+0pp) - -
SQL Validity 100% (+5pp) 1 🟢 -
Safety 90.5% (-5pp) 1 🟢 2 🔴
Time_to_first_token 2.7tok (-0.43tok) 22 🟢 7 🔴
Llm_calls 7.11 (+0.1) 11 🟢 11 🔴
Tool_calls 3.22 (+0.15) 13 🟢 9 🔴
Errors 0.02 (+0) 1 🟢 1 🔴
Llm_errors 0.01 (+0) 1 🟢 1 🔴
Tool_errors 0 (+0) - -
Prompt_tokens 23605.03tok (+181.49tok) 11 🟢 14 🔴
Prompt_cached_tokens 6932.6tok (-123.59tok) 13 🟢 11 🔴
Prompt_cache_creation_tokens 0tok (+0tok) - -
Prompt_cache_creation_5m_tokens 0tok (+0tok) - -
Prompt_cache_creation_1h_tokens 0tok (+0tok) - -
Completion_tokens 632.62tok (+12.53tok) 12 🟢 17 🔴
Completion_reasoning_tokens 104.78tok (-3.95tok) 12 🟢 14 🔴
Completion_accepted_prediction_tokens 0tok (+0tok) - -
Completion_rejected_prediction_tokens 0tok (+0tok) - -
Completion_audio_tokens 0tok (+0tok) - -
Total_tokens 24237.66tok (+194.02tok) 12 🟢 17 🔴
Estimated_cost 0$ (+0$) 11 🟢 16 🔴
Duration 15.5s (+0.22s) 15 🟢 14 🔴
Llm_duration 9.52s (-1.73s) 23 🟢 6 🔴

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants