Skip to content

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

feat(studio): add api keys to connect modal (#42118)

Charis842722def812
diff --git a/apps/studio/components/interfaces/Connect/ApiKeysTabContent.tsx b/apps/studio/components/interfaces/Connect/ApiKeysTabContent.tsx
new file mode 100644
index 00000000000..e1a486efbb8
--- /dev/null
+++ b/apps/studio/components/interfaces/Connect/ApiKeysTabContent.tsx
@@ -0,0 +1,77 @@
+import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { useParams } from 'common'
+import { AlertCircle, ExternalLink, Loader2 } from 'lucide-react'
+import Link from 'next/link'
+import type { ReactNode } from 'react'
+
+import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
+import { Button } from 'ui'
+import { Input } from 'ui-patterns/DataInputs/Input'
+import type { projectKeys } from './Connect.types'
+
+function KeyRow({ label, value }: { label: ReactNode; value: string }) {
+ return (
+ <div className="flex flex-col gap-5 lg:grid lg:grid-cols-12">
+ <div className="col-span-4">
+ <h3 className="text-sm text-foreground">{label}</h3>
+ </div>
+ <div className="col-span-8">
+ <Input readOnly copy className="font-mono" value={value} />
+ </div>
+ </div>
+ )
+}
+
+export function ApiKeysTabContent({ projectKeys }: { projectKeys: projectKeys }) {
+ const { ref: projectRef } = useParams()
+
+ const { isLoading: isLoadingPermissions, can: canReadAPIKeys } = useAsyncCheckPermissions(
+ PermissionAction.SECRETS_READ,
+ '*'
+ )
+
+ if (isLoadingPermissions) {
+ return (
+ <div className="flex items-center justify-center py-8 space-x-2">
+ <Loader2 className="animate-spin" size={16} strokeWidth={1.5} />
+ <p className="text-sm text-foreground-light">Retrieving API keys</p>
+ </div>
+ )
+ }
+
+ if (!canReadAPIKeys) {
+ return (
+ <div className="flex items-center py-8 space-x-2">
+ <AlertCircle size={16} strokeWidth={1.5} />
+ <p className="text-sm text-foreground-light">You don't have permission to view API keys.</p>
+ </div>
+ )
+ }
+
+ return (
+ <div className="flex flex-col gap-8">
+ <KeyRow label="Project URL" value={projectKeys.apiUrl ?? ''} />
+
+ <KeyRow label="Publishable Key" value={projectKeys.publishableKey ?? ''} />
+
+ <KeyRow
+ label={
+ <>
+ Anon Key <span className="text-foreground-lighter font-normal">(Legacy)</span>
+ </>
+ }
+ value={projectKeys.anonKey ?? ''}
+ />
+
+ {/* Footer */}
+ <div className="gap-5 lg:grid lg:grid-cols-12">
+ <div className="col-start-5 col-span-8 pl-2 flex items-center justify-between">
+ <p className="text-xs text-foreground-lighter">For secret keys, see API settings.</p>
+ <Button asChild type="default" icon={<ExternalLink size={14} />}>
+ <Link href={`/project/${projectRef}/settings/api-keys`}>API settings</Link>
+ </Button>
+ </div>
+ </div>
+ </div>
+ )
+}
diff --git a/apps/studio/components/interfaces/Connect/Connect.constants.ts b/apps/studio/components/interfaces/Connect/Connect.constants.ts
index 51ec0adf146..1ca5fc7b42d 100644
--- a/apps/studio/components/interfaces/Connect/Connect.constants.ts
+++ b/apps/studio/components/interfaces/Connect/Connect.constants.ts
@@ -378,6 +378,7 @@ export const CONNECTION_TYPES = [
{ key: 'frameworks', label: 'App Frameworks', obj: FRAMEWORKS },
{ key: 'mobiles', label: 'Mobile Frameworks', obj: MOBILES },
{ key: 'orms', label: 'ORMs', obj: ORMS },
+ { key: 'api-keys', label: 'API Keys', obj: [] },
{ key: 'mcp', label: 'MCP', obj: [] },
]
diff --git a/apps/studio/components/interfaces/Connect/Connect.tsx b/apps/studio/components/interfaces/Connect/Connect.tsx
index 9da0725aacf..0221bbf7f09 100644
--- a/apps/studio/components/interfaces/Connect/Connect.tsx
+++ b/apps/studio/components/interfaces/Connect/Connect.tsx
@@ -4,6 +4,7 @@ import { ExternalLink, Plug } from 'lucide-react'
import { parseAsBoolean, parseAsString, useQueryState } from 'nuqs'
import { useEffect, useMemo, useState } from 'react'
+import { ApiKeysTabContent } from 'components/interfaces/Connect/ApiKeysTabContent'
import { DatabaseConnectionString } from 'components/interfaces/Connect/DatabaseConnectionString'
import { McpTabContent } from 'components/interfaces/Connect/McpTabContent'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
@@ -412,6 +413,18 @@ export const Connect = () => {
)
}
+ if (type.key === 'api-keys') {
+ return (
+ <TabsContent_Shadcn_
+ key="api-keys"
+ value="api-keys"
+ className={cn(DIALOG_PADDING_X, DIALOG_PADDING_Y, '!mt-0')}
+ >
+ <ApiKeysTabContent projectKeys={projectKeys} />
+ </TabsContent_Shadcn_>
+ )
+ }
+
const connectionTabMap: Record<
string,
'App Frameworks' | 'Mobile Frameworks' | 'ORMs'