Skip to content

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

fix(studio): align rls confirmation dialogs (#45961)

Danny White1470c5102121
diff --git a/apps/design-system/content/docs/components/alert-dialog.mdx b/apps/design-system/content/docs/components/alert-dialog.mdx
index fe0508be5a4..d46fb5727eb 100644
--- a/apps/design-system/content/docs/components/alert-dialog.mdx
+++ b/apps/design-system/content/docs/components/alert-dialog.mdx
@@ -12,7 +12,10 @@ source:
Alert Dialog interrupts the user’s workflow to communicate critical information or confirm an action that cannot be taken lightly. It presents a short, focused message and requires the user to explicitly confirm or cancel before proceeding.
-Use Alert Dialog for actions such as deleting data, performing irreversible changes, or acknowledging important warnings where dismissal without a decision would be unsafe.
+Use Alert Dialog for actions such as deleting data, performing irreversible changes, or
+acknowledging important warnings where dismissal without a decision would be unsafe. It is the
+preferred starting point for critical confirmations when the decision can be explained in a short,
+focused message.
<ComponentPreview name="alert-dialog-demo" peekCode wide />
@@ -108,7 +111,7 @@ inline error feedback.
- **Use for dirty-form discard confirmation:** A short discard-confirmation step after a dirty form dismissal attempt (backdrop, Escape, or `Cancel`) is a valid Alert Dialog pattern. In Studio, prefer `DiscardChangesConfirmationDialog` for this flow.
- **Always provide a cancel action:** Include AlertDialogCancel so users can safely back out, in addition to supporting the Escape key.
- **Use AlertDialogBody for inline feedback:** If async actions can fail, render inline feedback such as an Admonition inside AlertDialogBody so spacing stays consistent.
-- **Avoid rich content:** If the dialog requires detailed explanations, callouts, or form inputs, use [Confirmation Modal](../fragments/confirmation-modal) or [Dialog](../components/dialog) instead.
+- **Avoid rich content:** If the decision requires detailed explanations, callouts, multiple paragraphs, or form inputs, move to [Confirmation Modal](../fragments/confirmation-modal) or [Dialog](../components/dialog) instead.
See [Modality](../ui-patterns/modality) for guidance on choosing the appropriate dialog pattern.
diff --git a/apps/design-system/content/docs/fragments/confirmation-modal.mdx b/apps/design-system/content/docs/fragments/confirmation-modal.mdx
index ac52d9beb11..1829773cde3 100644
--- a/apps/design-system/content/docs/fragments/confirmation-modal.mdx
+++ b/apps/design-system/content/docs/fragments/confirmation-modal.mdx
@@ -4,11 +4,16 @@ description: A modal dialog for confirmations that require additional context or
component: true
---
-Confirmation Modal is a convenience wrapper for confirmation flows that are more complex than a single paragraph but do not warrant a full custom dialog. It is built on top of [Dialog](../components/dialog) and provides a prop-based API for consistent confirmation patterns.
+Confirmation Modal is a convenience wrapper for confirmation flows that need more body structure
+than a concise Alert Dialog but do not warrant a full custom dialog. It is built on top of
+[Dialog](../components/dialog) and provides a prop-based API for consistent confirmation patterns.
Use Confirmation Modal when the user needs extra context to make a decision, such as explanatory copy, callouts, or small form elements, and the action is not so destructive that it requires typed confirmation.
-If the confirmation can be expressed as a single short paragraph, use [Alert Dialog](../components/alert-dialog). If the action is highly destructive and requires explicit typed intent, use [Text Confirm Dialog](../fragments/text-confirm-dialog). See [Modality](../ui-patterns/modality) for broader guidance on choosing the appropriate pattern.
+If a critical confirmation can be expressed as a single short paragraph, start with
+[Alert Dialog](../components/alert-dialog). If the action is highly destructive and requires
+explicit typed intent, use [Text Confirm Dialog](../fragments/text-confirm-dialog). See
+[Modality](../ui-patterns/modality) for broader guidance on choosing the appropriate pattern.
For dirty-form dismissal in dialogs/sheets, use the dedicated discard-confirmation pattern (`DiscardChangesConfirmationDialog` + `useConfirmOnClose`) instead of `ConfirmationModal`. Avoid creating custom wrapper components for this flow; wire `modalProps` from `useConfirmOnClose` directly into `DiscardChangesConfirmationDialog`.
@@ -55,7 +60,8 @@ export default function ConfirmationModalDemo() {
## Guidelines
-- **Use for moderate complexity:** Suitable when the confirmation requires more than a single sentence but does not need typed intent.
+- **Use for moderate complexity:** Suitable when the confirmation needs extra body content, such as multiple paragraphs, callouts, or simple supporting controls, but does not need typed intent.
+- **Do not use as the default critical confirmation:** Prefer [Alert Dialog](../components/alert-dialog) for short, critical confirmations with a clear confirm/cancel decision.
- **Do not use for standard dirty-form dismissal:** Prefer `DiscardChangesConfirmationDialog` for unsaved-changes prompts so copy, behavior, and wiring stay consistent across dialogs/sheets.
- **Avoid critical destruction:** Do not use for irreversible or high-risk actions that could benefit from stronger safeguards.
- **Keep content focused:** Include only the context needed to make the decision. If the dialog becomes a full flow, use a custom [Dialog](../components/dialog) instead.
diff --git a/apps/design-system/content/docs/ui-patterns/modality.mdx b/apps/design-system/content/docs/ui-patterns/modality.mdx
index 63938e858f5..ddb14d08fd0 100644
--- a/apps/design-system/content/docs/ui-patterns/modality.mdx
+++ b/apps/design-system/content/docs/ui-patterns/modality.mdx
@@ -30,9 +30,9 @@ Dialogs are centered overlays used for short, focused tasks. All dialogs should
There are quite a few dialog components, each suited to a different task or context:
-- [Alert Dialog](../components/alert-dialog) contains a single, short paragraph and an explicit action.
+- [Alert Dialog](../components/alert-dialog) is the preferred starting point for critical confirmations that can be explained in a single, short paragraph.
- [Text Confirm Dialog](../fragments/text-confirm-dialog) requires a textual response before the action is enabled.
-- [Confirmation Modal](../fragments/confirmation-modal) provides more flexible dialog body contents.
+- [Confirmation Modal](../fragments/confirmation-modal) provides more flexible dialog body contents when a confirmation needs extra context, callouts, or simple supporting controls.
- [Dialog](../components/dialog) is a generalized component for bespoke purposes.
#### Alert Dialog
@@ -49,7 +49,7 @@ There are quite a few dialog components, each suited to a different task or cont
#### Confirmation Modal
-[Confirmation Modal](../fragments/confirmation-modal) is a convenience wrapper for less-critical confirmations that require more than a single paragraph, such as additional context, callouts, or simple form elements.
+[Confirmation Modal](../fragments/confirmation-modal) is a convenience wrapper for confirmations that require more than a single paragraph, such as additional context, callouts, or simple form elements.
<ComponentPreview name="confirmation-modal-demo" />
diff --git a/apps/studio/components/interfaces/Auth/Policies/Policies.tsx b/apps/studio/components/interfaces/Auth/Policies/Policies.tsx
index aef35dcd525..9c73bc7b7d9 100644
--- a/apps/studio/components/interfaces/Auth/Policies/Policies.tsx
+++ b/apps/studio/components/interfaces/Auth/Policies/Policies.tsx
@@ -12,6 +12,7 @@ import {
} from '@/components/interfaces/Auth/Policies/PolicyTableRow'
import type { Policy } from '@/components/interfaces/Auth/Policies/PolicyTableRow/PolicyTableRow.utils'
import { ProtectedSchemaWarning } from '@/components/interfaces/Database/ProtectedSchemaWarning'
+import { RLSToggleDialog } from '@/components/interfaces/Database/RLSToggleDialog'
import { NoSearchResults } from '@/components/ui/NoSearchResults'
import { useDatabasePolicyDeleteMutation } from '@/data/database-policies/database-policy-delete-mutation'
import { useTableUpdateMutation } from '@/data/tables/table-update-mutation'
@@ -51,13 +52,10 @@ export const Policies = ({
}>()
const [selectedPolicyToDelete, setSelectedPolicyToDelete] = useState<any>({})
- const { mutate: updateTable, isPending: isUpdatingTable } = useTableUpdateMutation({
+ const { mutateAsync: updateTable, isPending: isUpdatingTable } = useTableUpdateMutation({
onError: (error) => {
toast.error(`Failed to toggle RLS: ${error.message}`)
},
- onSettled: () => {
- closeConfirmModal()
- },
})
const { mutate: deleteDatabasePolicy, isPending: isDeletingPolicy } =
@@ -102,7 +100,7 @@ export const Policies = ({
rls_enabled: !selectedTableToToggleRLS.rls_enabled,
}
- updateTable({
+ return updateTable({
projectRef: project?.ref!,
connectionString: project?.connectionString,
id: selectedTableToToggleRLS.id,
@@ -193,17 +191,14 @@ export const Policies = ({
onConfirm={onDeletePolicy}
/>
- <ConfirmationModal
- visible={selectedTableToToggleRLS !== undefined}
- variant={selectedTableToToggleRLS?.rls_enabled ? 'destructive' : 'default'}
- title={`${selectedTableToToggleRLS?.rls_enabled ? 'Disable' : 'Enable'} Row Level Security`}
- description={`Are you sure you want to ${
- selectedTableToToggleRLS?.rls_enabled ? 'disable' : 'enable'
- } Row Level Security (RLS) for the table “${selectedTableToToggleRLS?.name}”?`}
- confirmLabel={`${selectedTableToToggleRLS?.rls_enabled ? 'Disable' : 'Enable'} RLS`}
- confirmLabelLoading={`${selectedTableToToggleRLS?.rls_enabled ? 'Disabling' : 'Enabling'} RLS`}
- loading={isUpdatingTable}
- onCancel={closeConfirmModal}
+ <RLSToggleDialog
+ open={selectedTableToToggleRLS !== undefined}
+ tableName={selectedTableToToggleRLS?.name}
+ isEnabled={selectedTableToToggleRLS?.rls_enabled ?? false}
+ isSubmitting={isUpdatingTable}
+ onOpenChange={(open) => {
+ if (!open) closeConfirmModal()
+ }}
onConfirm={onToggleRLS}
/>
</>
diff --git a/apps/studio/components/interfaces/Database/RLSToggleDialog.tsx b/apps/studio/components/interfaces/Database/RLSToggleDialog.tsx
new file mode 100644
index 00000000000..9ad0b7e6ca1
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/RLSToggleDialog.tsx
@@ -0,0 +1,64 @@
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from 'ui'
+
+import { InlineLink } from '@/components/ui/InlineLink'
+import { DOCS_URL } from '@/lib/constants'
+
+interface RLSToggleDialogProps {
+ open: boolean
+ tableName?: string
+ isEnabled: boolean
+ isSubmitting?: boolean
+ onOpenChange: (open: boolean) => void
+ onConfirm: () => void | Promise<void>
+}
+
+export function RLSToggleDialog({
+ open,
+ isEnabled,
+ isSubmitting = false,
+ onOpenChange,
+ onConfirm,
+}: RLSToggleDialogProps) {
+ const title = isEnabled ? 'Disable Row Level Security' : 'Enable Row Level Security'
+ const description = isEnabled
+ ? 'This table will become publicly readable and writable. Anyone can view, add, update, or delete data in this table, and existing RLS policies will no longer apply.'
+ : 'RLS restricts table access until policies allow a request. Existing queries may stop returning rows until policies are added.'
+ const confirmLabel = isEnabled ? 'Disable RLS' : 'Enable RLS'
+ const confirmVariant = isEnabled ? 'danger' : 'primary'
+
+ return (
+ <AlertDialog open={open} onOpenChange={onOpenChange}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>{title}</AlertDialogTitle>
+ <AlertDialogDescription>
+ {description}{' '}
+ <InlineLink href={`${DOCS_URL}/guides/database/postgres/row-level-security`}>
+ Learn more
+ </InlineLink>
+ .
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ variant={confirmVariant}
+ loading={isSubmitting}
+ onClick={() => onConfirm()}
+ >
+ {confirmLabel}
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ )
+}
diff --git a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
index f005048cec3..08ddcd03b6c 100644
--- a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
@@ -21,7 +21,6 @@ import {
TooltipContent,
TooltipTrigger,
} from 'ui'
-import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
import { EnableIndexAdvisorDialog } from '../QueryPerformance/IndexAdvisor/EnableIndexAdvisorButton'
import { RoleImpersonationPopover } from '../RoleImpersonationSelector/RoleImpersonationPopover'
@@ -31,6 +30,7 @@ import { SecurityDefinerViewPopover } from './SecurityDefinerViewPopover'
import { ViewEntityAutofixSecurityModal } from './ViewEntityAutofixSecurityModal'
import { RefreshButton } from '@/components/grid/components/header/RefreshButton'
import { useTableIndexAdvisor } from '@/components/grid/context/TableIndexAdvisorContext'
+import { RLSToggleDialog } from '@/components/interfaces/Database/RLSToggleDialog'
import {
getEntityLintDetails,
getTablePoliciesUrl,
@@ -98,13 +98,10 @@ export const GridHeaderActions = ({ table, isRefetching }: GridHeaderActionsProp
const isRealtimeEnabled = useIsTableRealtimeEnabled({ id: table.id })
- const { mutate: updateTable, isPending: isUpdatingTable } = useTableUpdateMutation({
+ const { mutateAsync: updateTable, isPending: isUpdatingTable } = useTableUpdateMutation({
onError: (error) => {
toast.error(`Failed to toggle RLS: ${error.message}`)
},
- onSettled: () => {
- closeConfirmModal()
- },
})
const showHeaderActions = snap.selectedRows.size === 0
@@ -155,10 +152,6 @@ export const GridHeaderActions = ({ table, isRefetching }: GridHeaderActionsProp
table.schema
)
- const closeConfirmModal = () => {
- setRlsConfirmModalOpen(false)
- }
-
const onViewAPIDocs = () => {
appSnap.setActiveDocsSection(['entities', table.name])
appSnap.setShowProjectApiDocs(true)
@@ -181,7 +174,7 @@ export const GridHeaderActions = ({ table, isRefetching }: GridHeaderActionsProp
rls_enabled: !(isTable && table.rls_enabled),
}
- updateTable({
+ const updateTablePromise = updateTable({
projectRef: project?.ref!,
connectionString: project?.connectionString,
id: table.id,
@@ -195,6 +188,8 @@ export const GridHeaderActions = ({ table, isRefetching }: GridHeaderActionsProp
schema_name: table.schema,
table_name: table.name,
})
+
+ return updateTablePromise
}
return (
@@ -397,17 +392,12 @@ export const GridHeaderActions = ({ table, isRefetching }: GridHeaderActionsProp
/>
{isTable && (
- <ConfirmationModal
- visible={rlsConfirmModalOpen}
- variant={table.rls_enabled ? 'destructive' : 'default'}
- title={`${table.rls_enabled ? 'Disable' : 'Enable'} Row Level Security`}
- description={`Are you sure you want to ${
- table.rls_enabled ? 'disable' : 'enable'
- } Row Level Security for this table?`}
- confirmLabel={`${table.rls_enabled ? 'Disable' : 'Enable'} RLS`}
- confirmLabelLoading={`${table.rls_enabled ? 'Disabling' : 'Enabling'} RLS`}
- loading={isUpdatingTable}
- onCancel={closeConfirmModal}
+ <RLSToggleDialog
+ open={rlsConfirmModalOpen}
+ tableName={table.name}
+ isEnabled={table.rls_enabled}
+ isSubmitting={isUpdatingTable}
+ onOpenChange={setRlsConfirmModalOpen}
onConfirm={onToggleRLS}
/>
)}
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/RLSDisableModal.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/RLSDisableModal.tsx
deleted file mode 100644
index deba5b3c1e0..00000000000
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/RLSDisableModal.tsx
+++ /dev/null
@@ -1,54 +0,0 @@
-import { AlertOctagon, Lock, ShieldOff } from 'lucide-react'
-import { Admonition } from 'ui-patterns/admonition'
-
-import { DocsButton } from '@/components/ui/DocsButton'
-import { useCustomContent } from '@/hooks/custom-content/useCustomContent'
-import { DOCS_URL } from '@/lib/constants'
-
-export function RLSDisableModalContent() {
- const { docsRowLevelSecurityGuidePath } = useCustomContent(['docs:row_level_security_guide_path'])
-
- return (
- <div className="text-sm text-foreground-light grid gap-4">
- <div className="grid gap-1">
- <Admonition
- type="warning"
- layout="horizontal"
- description="This table will be publicly readable and writable. Anyone can edit or delete data in this table."
- />
- <ul className="mt-4 space-y-5">
- <li className="flex gap-3">
- <AlertOctagon size={14} />
- <span>All requests to this table will be accepted.</span>
- </li>
-
- <li className="flex gap-3">
- <ShieldOff size={14} />
- <span>Auth policies will not be enforced.</span>
- </li>
-
- <li className="flex gap-3">
- <Lock size={14} className="shrink-0" />
- <div>
- <strong>Before you turn off Row Level Security, consider:</strong>
- <ul className="space-y-2 mt-2">
- <li className="list-disc ml-4">
- Any personal information in this table will be publicly accessible.
- </li>
- <li className="list-disc ml-4">
- Anyone will be able to modify, add or delete any row in this table.
- </li>
- </ul>
- </div>
- </li>
- </ul>
- </div>
-
- <DocsButton
- abbrev={false}
- className="w-min mt-3"
- href={`${DOCS_URL}${docsRowLevelSecurityGuidePath}`}
- />
- </div>
- )
-}
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
index b7ce16ddcb2..2a4c1937870 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
@@ -3,7 +3,6 @@ import { useContext, useEffect, useMemo, useRef, useState } from 'react'
import { toast } from 'sonner'
import { Badge, Checkbox, Input, SidePanel } from 'ui'
import { Admonition } from 'ui-patterns'
-import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { ActionBar } from '../ActionBar'
@@ -16,7 +15,6 @@ import { ApiAccessToggle, type TableApiAccessHandlerWithHistoryReturn } from './
import { ColumnManagement } from './ColumnManagement'
import { ForeignKeysManagement } from './ForeignKeysManagement/ForeignKeysManagement'
import { HeaderTitle } from './HeaderTitle'
-import { RLSDisableModalContent } from './RLSDisableModal'
import { DEFAULT_COLUMNS } from './TableEditor.constants'
import type { ImportContent, TableField } from './TableEditor.types'
import {
@@ -26,6 +24,7 @@ import {
mergeForeignKeyMeta,
validateFields,
} from './TableEditor.utils'
+import { RLSToggleDialog } from '@/components/interfaces/Database/RLSToggleDialog'
import { DocsButton } from '@/components/ui/DocsButton'
import { useDatabasePublicationsQuery } from '@/data/database-publications/database-publications-query'
import { CONSTRAINT_TYPE, useTableConstraintsQuery } from '@/data/database/constraints-query'
@@ -586,19 +585,16 @@ export const TableEditor = ({
closePanel={() => setIsImportingSpreadsheet(false)}
/>
- <ConfirmationModal
- visible={rlsConfirmVisible}
- title="Turn off Row Level Security"
- confirmLabel="Confirm"
- size="medium"
- onCancel={() => setRlsConfirmVisible(false)}
+ <RLSToggleDialog
+ open={rlsConfirmVisible}
+ tableName={tableFields.name}
+ isEnabled={tableFields.isRLSEnabled}
+ onOpenChange={setRlsConfirmVisible}
onConfirm={() => {
- onUpdateField({ isRLSEnabled: !tableFields.isRLSEnabled })
+ onUpdateField({ isRLSEnabled: false })
setRlsConfirmVisible(false)
}}
- >
- <RLSDisableModalContent />
- </ConfirmationModal>
+ />
</SidePanel.Content>
{!isDuplicating && (
diff --git a/e2e/studio/features/rls-policies.spec.ts b/e2e/studio/features/rls-policies.spec.ts
index 34b1b2a2026..c7dfb6b3f7d 100644
--- a/e2e/studio/features/rls-policies.spec.ts
+++ b/e2e/studio/features/rls-policies.spec.ts
@@ -159,6 +159,18 @@ test.describe('RLS Policies', () => {
page.getByRole('heading', { name: 'Disable Row Level Security' }),
'RLS disable confirmation modal should appear'
).toBeVisible({ timeout: 50000 })
+ await expect(
+ page.getByText(
+ 'This table will become publicly readable and writable. Anyone can view, add, update, or delete data in this table, and existing RLS policies will no longer apply.'
+ ),
+ 'RLS disable confirmation should explain the access risk'
+ ).toBeVisible()
+ await expect(
+ page.getByRole('alertdialog').getByRole('link', { name: 'Learn more' })
+ ).toHaveAttribute(
+ 'href',
+ 'https://supabase.com/docs/guides/database/postgres/row-level-security'
+ )
// Confirm disabling RLS
await page.getByRole('button', { name: 'Disable RLS' }).click()
diff --git a/e2e/studio/features/table-editor.spec.ts b/e2e/studio/features/table-editor.spec.ts
index a11adcf6c1c..e149f30fd3d 100644
--- a/e2e/studio/features/table-editor.spec.ts
+++ b/e2e/studio/features/table-editor.spec.ts
@@ -176,7 +176,15 @@ testRunner('table editor', () => {
await expect(page.getByRole('link', { name: 'Add RLS policy' })).toBeVisible()
await page.getByRole('button', { name: `View ${tableNameRlsDisabled}` }).click()
- await expect(page.getByRole('button', { name: 'RLS disabled' })).toBeVisible()
+ await page.getByRole('button', { name: 'RLS disabled' }).click()
+ await page.getByRole('button', { name: 'Enable RLS for this table' }).click()
+ await expect(page.getByRole('heading', { name: 'Enable Row Level Security' })).toBeVisible()
+ await expect(
+ page.getByText(
+ 'RLS restricts table access until policies allow a request. Existing queries may stop returning rows until policies are added.'
+ )
+ ).toBeVisible()
+ await page.getByRole('button', { name: 'Cancel' }).click()
})
test('add enums and show enums on table', async ({ page, ref }) => {