Skip to content

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

Minor update to new API keys modal for disabling / reenabling legacy keys (#36554)

Joshen Limc8dbc57051ba
diff --git a/apps/studio/components/interfaces/Auth/Users/UsersV2.tsx b/apps/studio/components/interfaces/Auth/Users/UsersV2.tsx
index 495ab339596..63ee824ffb8 100644
--- a/apps/studio/components/interfaces/Auth/Users/UsersV2.tsx
+++ b/apps/studio/components/interfaces/Auth/Users/UsersV2.tsx
@@ -119,7 +119,7 @@ export const UsersV2 = () => {
}
)
- const { data: countData } = useUsersCountQuery({
+ const { data: countData, refetch: refetchCount } = useUsersCountQuery({
projectRef,
connectionString: project?.connectionString,
keywords: filterKeywords,
@@ -437,7 +437,10 @@ export const UsersV2 = () => {
icon={<RefreshCw />}
type="default"
loading={isRefetching && !isFetchingNextPage}
- onClick={() => refetch()}
+ onClick={() => {
+ refetch()
+ refetchCount()
+ }}
>
Refresh
</Button>
diff --git a/apps/studio/components/ui/ProjectSettings/ToggleLegacyApiKeys.tsx b/apps/studio/components/ui/ProjectSettings/ToggleLegacyApiKeys.tsx
index 9a8e4f18563..a24bc09ef89 100644
--- a/apps/studio/components/ui/ProjectSettings/ToggleLegacyApiKeys.tsx
+++ b/apps/studio/components/ui/ProjectSettings/ToggleLegacyApiKeys.tsx
@@ -1,14 +1,14 @@
+import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useState } from 'react'
import { toast } from 'sonner'
-import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useParams } from 'common'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { useToggleLegacyAPIKeysMutation } from 'data/api-keys/legacy-api-key-toggle-mutation'
import { useLegacyAPIKeysStatusQuery } from 'data/api-keys/legacy-api-keys-status-query'
import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'
-import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_, CriticalIcon } from 'ui'
import TextConfirmModal from 'ui-patterns/Dialogs/TextConfirmModal'
+import Panel from '../Panel'
export const ToggleLegacyApiKeysPanel = () => {
const { ref: projectRef } = useParams()
@@ -20,44 +20,49 @@ export const ToggleLegacyApiKeysPanel = () => {
const { can: canUpdateAPIKeys, isSuccess: isPermissionsSuccess } =
useAsyncCheckProjectPermissions(PermissionAction.SECRETS_WRITE, '*')
+ const { enabled: isLegacyKeysEnabled } = legacyAPIKeysStatusData || {}
+
if (!(isLegacyAPIKeysStatusSuccess && isPermissionsSuccess)) {
return null
}
return (
<section>
- <Alert_Shadcn_ variant={legacyAPIKeysStatusData.enabled ? 'destructive' : 'warning'}>
- <CriticalIcon />
- <AlertTitle_Shadcn_>
- {legacyAPIKeysStatusData.enabled
- ? 'Disabling your legacy API keys may cause your applications to break.'
- : 'Re-enabling your legacy API keys may expose your applications to security risks.'}
- </AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_>
- {legacyAPIKeysStatusData.enabled
- ? 'Make sure you are no longer using your legacy API keys before proceeding.'
- : "Make sure you've tested your RLS policies."}
- </AlertDescription_Shadcn_>
- <div className="mt-2">
- <ButtonTooltip
- type={legacyAPIKeysStatusData.enabled ? 'danger' : 'warning'}
- onClick={() => setIsConfirmOpen(true)}
- disabled={!canUpdateAPIKeys}
- tooltip={{
- content: {
- side: 'bottom',
- text: !canUpdateAPIKeys
- ? 'You need additional permissions to enable or disable JWT-based API keys'
- : undefined,
- },
- }}
- >
- {legacyAPIKeysStatusData.enabled
- ? 'Disable JWT-based API keys'
- : 'Re-enable JWT-based API keys'}
- </ButtonTooltip>
- </div>
- </Alert_Shadcn_>
+ <Panel>
+ <Panel.Content>
+ <div className="flex justify-between">
+ <div>
+ <p className="text-sm">
+ {isLegacyKeysEnabled ? 'Disable legacy API keys' : 'Re-enabling legacy API keys'}
+ </p>
+ <p className="text-foreground-light text-sm">
+ {isLegacyKeysEnabled
+ ? 'Make sure you are no longer using your legacy API keys before proceeding.'
+ : 'Ensure that your RLS policies are in place prior to re-enabling legacy keys.'}
+ </p>
+ </div>
+ <div className="flex items-center">
+ <ButtonTooltip
+ type="default"
+ onClick={() => setIsConfirmOpen(true)}
+ disabled={!canUpdateAPIKeys}
+ tooltip={{
+ content: {
+ side: 'bottom',
+ text: !canUpdateAPIKeys
+ ? 'You need additional permissions to enable or disable JWT-based API keys'
+ : undefined,
+ },
+ }}
+ >
+ {legacyAPIKeysStatusData.enabled
+ ? 'Disable JWT-based API keys'
+ : 'Re-enable JWT-based API keys'}
+ </ButtonTooltip>
+ </div>
+ </div>
+ </Panel.Content>
+ </Panel>
<ToggleApiKeysModal
visible={isConfirmOpen}
@@ -78,6 +83,7 @@ const ToggleApiKeysModal = ({
legacyAPIKeysStatusData: { enabled: boolean }
}) => {
const { ref: projectRef } = useParams()
+ const { enabled: isLegacyKeysEnabled } = legacyAPIKeysStatusData || {}
const { mutate: toggleLegacyAPIKey, isLoading: isTogglingLegacyAPIKey } =
useToggleLegacyAPIKeysMutation()
@@ -102,27 +108,37 @@ const ToggleApiKeysModal = ({
return (
<TextConfirmModal
+ size="medium"
visible={visible}
onCancel={() => onClose()}
onConfirm={onToggleLegacyAPIKeysEnabled}
- title={
- legacyAPIKeysStatusData.enabled ? 'Disable JWT-based keys' : 'Re-enable JWT-based keys'
- }
- confirmString={legacyAPIKeysStatusData.enabled ? 'disable' : 're-enable'}
- confirmLabel={`Yes, ${legacyAPIKeysStatusData.enabled ? 'disable' : 're-enable'} anon and service_role`}
- confirmPlaceholder={legacyAPIKeysStatusData.enabled ? 'disable' : 're-enable'}
+ title={isLegacyKeysEnabled ? 'Disable JWT-based keys' : 'Re-enable JWT-based keys'}
+ confirmString={isLegacyKeysEnabled ? 'disable' : 're-enable'}
+ confirmLabel={`Confirm to ${isLegacyKeysEnabled ? 'disable' : 're-enable'} anon and service_role`}
+ confirmPlaceholder={isLegacyKeysEnabled ? 'disable' : 're-enable'}
loading={isTogglingLegacyAPIKey}
- variant={legacyAPIKeysStatusData.enabled ? 'destructive' : 'default'}
+ variant={isLegacyKeysEnabled ? 'destructive' : 'default'}
alert={
- legacyAPIKeysStatusData.enabled
+ isLegacyKeysEnabled
? {
- title: 'Disabling can cause downtime!',
- description: `If you disable your anon and service_role keys while they are in use, your applications will stop functioning. All API endpoints will receive HTTP 401 Unauthorized. Make sure you are no longer using them before proceeding.`,
+ title: 'Ensure legacy keys are no longer in use before disabling',
+ description: (
+ <span className="prose text-sm">
+ Disabling <code>anon</code> and <code>service_role</code> keys while they are in
+ use will cause downtime for your application. Ensure they are no longer in use
+ before proceeding.
+ </span>
+ ),
}
: {
- title: 'Prefer publishable and secret keys',
- description:
- 'While re-enabling anon and service_role keys makes sense in some cases, a better and more secure alternative is the publishable or secret key. Consider using those before proceeding!',
+ title: 'Publishable and secret keys are preferred',
+ description: (
+ <span className="prose text-sm">
+ Re-enabling <code>anon</code> and <code>service_role</code> keys may be
+ appropriate in certain cases, but using a publishable and secret key is more
+ secure. We recommend against re-enabling legacy API keys
+ </span>
+ ),
}
}
/>
diff --git a/packages/ui-patterns/src/Dialogs/TextConfirmModal.tsx b/packages/ui-patterns/src/Dialogs/TextConfirmModal.tsx
index 69b281d5759..178b1ea7a59 100644
--- a/packages/ui-patterns/src/Dialogs/TextConfirmModal.tsx
+++ b/packages/ui-patterns/src/Dialogs/TextConfirmModal.tsx
@@ -41,7 +41,7 @@ export interface TextConfirmModalProps {
alert?: {
base?: React.ComponentProps<typeof Alert_Shadcn_>
title?: string
- description?: string
+ description?: string | ReactNode
}
input?: React.ComponentProps<typeof Input_Shadcn_>
label?: React.ComponentProps<typeof FormLabel_Shadcn_>