Files
supabase/apps/studio/components/interfaces/APIKeys/CreateNewAPIKeysButton.tsx
Jonathan Summers-Muir 9318404e61 Feat/api keys rollout prep (#35559)
* first pass

* init

* updated types

* fix up key reveal

* Update QuickKeyCopy.tsx

* remove quick key copy

* api key pill now only allows reveal and copy if you have perm

* Update LegacyAPIKeys.tsx

* fix up layouts

* fix copy

* Fix action menu dropdown position, few small nudges

* Remove unused files.

* Remove the hardcoded and rename the feature flag for basic API keys.

* add support for name and description, some smaller improvements

* Fix the trims for the description.

---------

Co-authored-by: Terry Sutton <saltcod@gmail.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
Co-authored-by: Stojan Dimitrovski <sdimitrovski@gmail.com>
2025-05-27 15:50:42 +02:00

73 lines
2.1 KiB
TypeScript

import { useState } from 'react'
import { useParams } from 'common'
import { useAPIKeyCreateMutation } from 'data/api-keys/api-key-create-mutation'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
Button,
} from 'ui'
export const CreateNewAPIKeysButton = () => {
const { ref: projectRef } = useParams()
const [createKeysDialogOpen, setCreateKeysDialogOpen] = useState(false)
const [isCreatingKeys, setIsCreatingKeys] = useState(false)
const { mutate: createAPIKey } = useAPIKeyCreateMutation()
const handleCreateNewApiKeys = async () => {
if (!projectRef) return
setIsCreatingKeys(true)
try {
// Create publishable key
await createAPIKey({
projectRef,
type: 'publishable',
name: 'default',
})
// Create secret key
await createAPIKey({
projectRef,
type: 'secret',
name: 'default',
})
setCreateKeysDialogOpen(false)
} catch (error) {
console.error('Failed to create API keys:', error)
} finally {
setIsCreatingKeys(false)
}
}
return (
<AlertDialog open={createKeysDialogOpen} onOpenChange={setCreateKeysDialogOpen}>
<Button onClick={() => setCreateKeysDialogOpen(true)}>Create new API keys</Button>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Create new API keys</AlertDialogTitle>
<AlertDialogDescription>
This will create a default publishable key and a default secret key named{' '}
<code>default</code>. These keys are required to connect your application to your
Supabase project.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={handleCreateNewApiKeys} disabled={isCreatingKeys}>
{isCreatingKeys ? 'Creating...' : 'Create keys'}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)
}