Repository navigation
feat: surface send-email hook status in template UI and hook deletion dialog - #46319
Conversation
…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]>
🎭 Playwright Test ResultsDetails
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
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]>
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]>
There was a problem hiding this comment.
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 winSame dual-admonition overlap as in
EmailTemplates.tsx.When
isTemplateEditBlockedandhasSendEmailHookare both true, the SMTP-restriction notice and the "templates bypassed" notice render together, which is contradictory. Consider the same gating suggested inEmailTemplates.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
📒 Files selected for processing (6)
apps/studio/components/interfaces/Auth/EmailTemplates/EmailTemplates.tsxapps/studio/components/interfaces/Auth/EmailTemplates/SendEmailHookActiveAdmonition.tsxapps/studio/components/interfaces/Auth/EmailTemplates/TemplateEditor.test.tsxapps/studio/components/interfaces/Auth/Hooks/DeleteSendEmailHookConfirmationDialog.tsxapps/studio/components/interfaces/Auth/Hooks/HooksListing.tsxapps/studio/pages/project/[ref]/auth/templates/[templateId].tsx
There was a problem hiding this comment.
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]>
| const { mutate: updateAuthHooks, isPending: isDeletingAuthHook } = useAuthHooksUpdateMutation({ | ||
| const { | ||
| mutate: updateAuthHooks, | ||
| mutateAsync: updateAuthHooksAsync, |
There was a problem hiding this comment.
we could just use the original mutate one - otherwise mutateAsync requires error handling within a try catch block too
| const handleDeleteSendEmailHook = async (): Promise<void> => { | ||
| if (!selectedHookForDeletion) return | ||
| await updateAuthHooksAsync({ | ||
| projectRef: projectRef!, | ||
| config: { | ||
| [selectedHookForDeletion.enabledKey]: false, | ||
| [selectedHookForDeletion.uriKey]: null, | ||
| [selectedHookForDeletion.secretsKey]: null, | ||
| }, | ||
| }) | ||
| } | ||
|
|
There was a problem hiding this comment.
this also seems like repeated logic with the confirmation modal below - modal can use this method
| <DeleteSendEmailHookConfirmationDialog | ||
| open={selectedHookForDeletion?.id === 'send-email'} | ||
| onOpenChange={(open) => { | ||
| if (!open) setSelectedHookForDeletion(null) | ||
| }} | ||
| onConfirm={handleDeleteSendEmailHook} | ||
| willLockTemplates={willLockTemplatesOnSendEmailDelete} | ||
| /> | ||
|
|
||
| <ConfirmationModal |
There was a problem hiding this comment.
thinking we could probably extract this into a generic DeleteHookConfirmationDialog and handle the logic there
| )} | ||
| {hasSendEmailHook && ( | ||
| <div className="mb-4"> | ||
| <SendEmailHookActiveAdmonition /> |
There was a problem hiding this comment.
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}> |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
"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?
There was a problem hiding this comment.
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 winInclude schema changes in the revoke check.
If a hook moves from
public.fntoprivate.fn, this branch skipsgetRevokePermissionStatements()because the function name is unchanged. That leavessupabase_auth_adminaccess 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 winPrevent “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
📒 Files selected for processing (5)
apps/studio/components/interfaces/Auth/EmailTemplates/SendEmailHookActiveAdmonition.tsxapps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsxapps/studio/components/interfaces/Auth/Hooks/DeleteHookConfirmationDialog.tsxapps/studio/components/interfaces/Auth/Hooks/HookCard.tsxapps/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
left a comment
There was a problem hiding this comment.
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 🙏 🙏
Braintrust eval report
|



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
SendEmailHookActiveAdmonitionis shown on both the template list and individual template editor pages whenHOOK_SEND_EMAIL_ENABLEDandHOOK_SEND_EMAIL_URIare set: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:The dialog stays open with a loading state while the deletion is in-flight and closes on success.
Summary by CodeRabbit