Skip to content

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

chore/ add API keys upcoming change notice (#29664)

Jonathan Summers-Muir0dee525177bf
diff --git a/apps/studio/components/interfaces/Home/Connect/Connect.tsx b/apps/studio/components/interfaces/Home/Connect/Connect.tsx
index 425904e5c77..d00330491b2 100644
--- a/apps/studio/components/interfaces/Home/Connect/Connect.tsx
+++ b/apps/studio/components/interfaces/Home/Connect/Connect.tsx
@@ -30,6 +30,7 @@ import { CONNECTION_TYPES, ConnectionType, FRAMEWORKS, MOBILES, ORMS } from './C
import { getContentFilePath } from './Connect.utils'
import ConnectDropdown from './ConnectDropdown'
import ConnectTabContent from './ConnectTabContent'
+import Panel from 'components/ui/Panel'
const Connect = () => {
const { ref: projectRef } = useParams()
@@ -254,7 +255,20 @@ const Connect = () => {
<p className="text-xs text-foreground-lighter my-3">
Add the following files below to your application
</p>
- <ConnectTabContent projectKeys={projectKeys} filePath={filePath} />
+ <ConnectTabContent
+ projectKeys={projectKeys}
+ filePath={filePath}
+ className="rounded-b-none"
+ />
+ <Panel.Notice
+ className="border border-t-0 rounded-lg rounded-t-none"
+ title="New API keys coming Q4 2024"
+ description={`
+\`anon\` and \`service_role\` API keys will be changing to \`publishable\` and \`secret\` API keys.
+`}
+ href="https://github.com/orgs/supabase/discussions/29260"
+ buttonText="Read the announcement"
+ />
</TabsContent_Shadcn_>
)
})}
diff --git a/apps/studio/components/interfaces/Home/Connect/ConnectTabContent.tsx b/apps/studio/components/interfaces/Home/Connect/ConnectTabContent.tsx
index b15193d5c0c..59eac3804d6 100644
--- a/apps/studio/components/interfaces/Home/Connect/ConnectTabContent.tsx
+++ b/apps/studio/components/interfaces/Home/Connect/ConnectTabContent.tsx
@@ -1,5 +1,6 @@
import { useParams } from 'common'
import dynamic from 'next/dynamic'
+import { forwardRef, HTMLAttributes } from 'react'
import { getConnectionStrings } from 'components/interfaces/Settings/Database/DatabaseSettings/DatabaseSettings.utils'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
@@ -7,8 +8,9 @@ import { useProjectSettingsQuery } from 'data/config/project-settings-query'
import { usePoolingConfigurationQuery } from 'data/database/pooling-configuration-query'
import { pluckObjectFields } from 'lib/helpers'
import type { projectKeys } from './Connect.types'
+import { cn } from 'ui'
-interface ConnectContentTabProps {
+interface ConnectContentTabProps extends HTMLAttributes<HTMLDivElement> {
projectKeys: projectKeys
filePath: string
connectionStringPooler?: {
@@ -18,58 +20,62 @@ interface ConnectContentTabProps {
connectionStringDirect?: string
}
-const ConnectTabContentNew = ({ projectKeys, filePath }: ConnectContentTabProps) => {
- const { ref } = useParams()
- const { data } = useProjectSettingsQuery({ projectRef: ref })
- const { data: poolingInfo } = usePoolingConfigurationQuery({ projectRef: ref })
+const ConnectTabContentNew = forwardRef<HTMLDivElement, ConnectContentTabProps>(
+ ({ projectKeys, filePath, ...props }, ref) => {
+ const { ref: projectRef } = useParams()
+ const { data } = useProjectSettingsQuery({ projectRef })
+ const { data: poolingInfo } = usePoolingConfigurationQuery({ projectRef })
- const { project } = data ?? {}
- const DB_FIELDS = ['db_host', 'db_name', 'db_port', 'db_user', 'inserted_at']
- const emptyState = { db_user: '', db_host: '', db_port: '', db_name: '' }
- const connectionInfo = pluckObjectFields(project || emptyState, DB_FIELDS)
- const poolingConfiguration = poolingInfo?.find((x) => x.database_type === 'PRIMARY')
+ const { project } = data ?? {}
+ const DB_FIELDS = ['db_host', 'db_name', 'db_port', 'db_user', 'inserted_at']
+ const emptyState = { db_user: '', db_host: '', db_port: '', db_name: '' }
+ const connectionInfo = pluckObjectFields(project || emptyState, DB_FIELDS)
+ const poolingConfiguration = poolingInfo?.find((x) => x.database_type === 'PRIMARY')
- const connectionStringsPooler =
- poolingConfiguration !== undefined
- ? getConnectionStrings(connectionInfo, poolingConfiguration, {
- projectRef: ref,
- usePoolerConnection: true,
- })
- : { uri: '' }
- const connectionStringsDirect =
- poolingConfiguration !== undefined
- ? getConnectionStrings(connectionInfo, poolingConfiguration, {
- projectRef: ref,
- usePoolerConnection: false,
- })
- : { uri: '' }
- const connectionStringPoolerTransaction = connectionStringsPooler.uri
- const connectionStringPoolerSession = connectionStringsPooler.uri.replace('6543', '5432')
+ const connectionStringsPooler =
+ poolingConfiguration !== undefined
+ ? getConnectionStrings(connectionInfo, poolingConfiguration, {
+ projectRef,
+ usePoolerConnection: true,
+ })
+ : { uri: '' }
+ const connectionStringsDirect =
+ poolingConfiguration !== undefined
+ ? getConnectionStrings(connectionInfo, poolingConfiguration, {
+ projectRef,
+ usePoolerConnection: false,
+ })
+ : { uri: '' }
+ const connectionStringPoolerTransaction = connectionStringsPooler.uri
+ const connectionStringPoolerSession = connectionStringsPooler.uri.replace('6543', '5432')
- const ContentFile = dynamic<ConnectContentTabProps>(
- () => import(`./content/${filePath}/content`),
- {
- loading: () => (
- <div className="p-4 min-h-[331px]">
- <GenericSkeletonLoader />
- </div>
- ),
- }
- )
+ const ContentFile = dynamic<ConnectContentTabProps>(
+ () => import(`./content/${filePath}/content`),
+ {
+ loading: () => (
+ <div className="p-4 min-h-[331px]">
+ <GenericSkeletonLoader />
+ </div>
+ ),
+ }
+ )
- return (
- <div className="border rounded-lg">
- <ContentFile
- projectKeys={projectKeys}
- filePath={filePath}
- connectionStringPooler={{
- transaction: connectionStringPoolerTransaction,
- session: connectionStringPoolerSession,
- }}
- connectionStringDirect={connectionStringsDirect.uri}
- />
- </div>
- )
-}
+ return (
+ <div ref={ref} {...props} className={cn('border rounded-lg', props.className)}>
+ <ContentFile
+ projectKeys={projectKeys}
+ filePath={filePath}
+ connectionStringPooler={{
+ transaction: connectionStringPoolerTransaction,
+ session: connectionStringPoolerSession,
+ }}
+ connectionStringDirect={connectionStringsDirect.uri}
+ />
+ </div>
+ )
+ }
+)
+
+ConnectTabContentNew.displayName = 'ConnectTabContentNew'
export default ConnectTabContentNew
diff --git a/apps/studio/components/ui/Panel.tsx b/apps/studio/components/ui/Panel.tsx
index 651e551def7..1f01edc534a 100644
--- a/apps/studio/components/ui/Panel.tsx
+++ b/apps/studio/components/ui/Panel.tsx
@@ -1,5 +1,7 @@
-import { PropsWithChildren, ReactNode } from 'react'
-import { Loading, cn } from 'ui'
+import { Megaphone } from 'lucide-react'
+import { forwardRef, PropsWithChildren, ReactNode } from 'react'
+import ReactMarkdown from 'react-markdown'
+import { Badge, Button, Loading, cn } from 'ui'
interface PanelProps {
className?: string
@@ -53,5 +55,81 @@ function Content({ children, className }: { children: ReactNode; className?: str
return <div className={cn('px-6 py-4', className)}>{children}</div>
}
+const PanelNotice = forwardRef<
+ HTMLDivElement,
+ {
+ className?: string | false
+ title?: string
+ description?: string
+ href?: string
+ buttonText?: string
+ }
+>(({ className, title, description, href, buttonText, ...props }, ref) => {
+ return (
+ <div
+ ref={ref}
+ {...props}
+ className={cn(
+ 'relative px-6 py-5 bg-studio flex flex-col lg:flex-row lg:justify-between gap-6 overflow-hidden lg:items-center',
+ className
+ )}
+ >
+ <div
+ className="absolute inset-0 -mt-[5px]"
+ style={{
+ backgroundImage: `
+ linear-gradient(to right, hsl(var(--background-200)/1) 0%, hsl(var(--background-200)/1) 30%, hsl(var(--background-200)/0) 100%),
+ linear-gradient(to right, hsl(var(--border-default)/0.33) 1px, transparent 1px),
+ linear-gradient(to bottom, hsl(var(--border-default)/0.33) 1px, transparent 1px)
+ `,
+ backgroundSize: '100% 100%, 15px 15px, 15px 15px',
+ backgroundPosition: '0 0, 0 0, 0 0',
+ }}
+ ></div>
+ <div className="relative flex flex-col gap-1">
+ <div className="flex flex-row items-center -space-x-px">
+ <Badge
+ variant={'default'}
+ className="
+ rounded-r-none
+ pr-2
+ flex-shrink-0 gap-1.5 border-dashed bg-opacity-0 bg-surface-400 text-foreground-lighter"
+ >
+ <Megaphone size={16} strokeWidth={1.2} />
+ Upcoming change
+ </Badge>
+ <Badge
+ variant={'default'}
+ className="
+ rounded-l-none
+ flex-shrink-0 gap-1.5 bg-opacity-0 bg-surface-400 text-foreground-lighter border-l-0"
+ >
+ <span className="text-foreground text-xs">{title}</span>
+ </Badge>
+ {/* <span className="font-medium text-foreground text-sm">{title}</span> */}
+ </div>
+ {description && (
+ <span className="text-foreground-light text-sm flex flex-col gap-0">
+ <ReactMarkdown className="prose text-xs max-w-none [&_p]:mt-2 [&_p]:mb-0">
+ {description}
+ </ReactMarkdown>
+ </span>
+ )}
+ </div>
+
+ {href && (
+ <div>
+ <Button size="tiny" type="default" className="text-xs" asChild>
+ <a href={href}>{buttonText ?? 'Read the accouncement'}</a>
+ </Button>
+ </div>
+ )}
+ </div>
+ )
+})
+
+PanelNotice.displayName = 'PanelNotice'
+
Panel.Content = Content
+Panel.Notice = PanelNotice
export default Panel
diff --git a/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx b/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx
index a8a6a9908ff..60df961219c 100644
--- a/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx
+++ b/apps/studio/components/ui/ProjectSettings/DisplayApiSettings.tsx
@@ -10,7 +10,7 @@ import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { DEFAULT_PROJECT_API_SERVICE_ID } from 'lib/constants'
import { AlertCircle, BookOpen, Loader2 } from 'lucide-react'
-const DisplayApiSettings = () => {
+const DisplayApiSettings = ({ legacy }: { legacy?: boolean }) => {
const { ref: projectRef } = useParams()
const {
@@ -38,92 +38,114 @@ const DisplayApiSettings = () => {
const isApiKeysEmpty = apiKeys.length === 0
return (
- <Panel
- title={
- <div className="space-y-3">
- <h5 className="text-base">Project API keys</h5>
- <p className="text-sm text-foreground-light">
- Your API is secured behind an API gateway which requires an API Key for every request.
- <br />
- You can use the keys below in the Supabase client libraries.
- <br />
- <a href="https://supabase.com/docs#client-libraries" target="_blank" rel="noreferrer">
- <Button icon={<BookOpen />} type="default" className="mt-4">
- Client Docs
- </Button>
- </a>
- </p>
- </div>
- }
- >
- {isProjectSettingsError || isJwtSecretUpdateStatusError ? (
- <div className="flex items-center justify-center py-8 space-x-2">
- <AlertCircle size={16} strokeWidth={1.5} />
- <p className="text-sm text-foreground-light">
- {isProjectSettingsError ? 'Failed to retrieve API keys' : 'Failed to update JWT secret'}
- </p>
- </div>
- ) : isApiKeysEmpty || isProjectSettingsLoading || isJwtSecretUpdateStatusLoading ? (
- <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">
- {isProjectSettingsLoading || isApiKeysEmpty
- ? 'Retrieving API keys'
- : 'JWT secret is being updated'}
- </p>
- </div>
- ) : (
- apiKeys.map((x, i: number) => (
- <Panel.Content
- key={x.api_key}
- className={
- i >= 1 &&
- 'border-t border-panel-border-interior-light [[data-theme*=dark]_&]:border-panel-border-interior-dark'
- }
- >
- <Input
- readOnly
- disabled
- layout="horizontal"
- className="input-mono"
- // @ts-ignore
- label={
- <>
- {x.tags?.split(',').map((x, i: number) => (
- <code key={`${x}${i}`} className="text-xs text-code">
- {x}
- </code>
- ))}
- {x.tags === 'service_role' && (
- <>
- <code className="bg-red-900 text-xs text-white">secret</code>
- </>
- )}
- {x.tags === 'anon' && <code className="text-xs text-code">public</code>}
- </>
+ <>
+ <Panel
+ title={
+ !legacy && (
+ <div className="space-y-3">
+ <h5 className="text-base">Project API Keys</h5>
+ <p className="text-sm text-foreground-light">
+ Your API is secured behind an API gateway which requires an API Key for every
+ request.
+ <br />
+ You can use the keys below in the Supabase client libraries.
+ <br />
+ <a
+ href="https://supabase.com/docs#client-libraries"
+ target="_blank"
+ rel="noreferrer"
+ >
+ <Button icon={<BookOpen />} type="default" className="mt-4">
+ Client Docs
+ </Button>
+ </a>
+ </p>
+ </div>
+ )
+ }
+ >
+ {isProjectSettingsError || isJwtSecretUpdateStatusError ? (
+ <div className="flex items-center justify-center py-8 space-x-2">
+ <AlertCircle size={16} strokeWidth={1.5} />
+ <p className="text-sm text-foreground-light">
+ {isProjectSettingsError
+ ? 'Failed to retrieve API keys'
+ : 'Failed to update JWT secret'}
+ </p>
+ </div>
+ ) : isApiKeysEmpty || isProjectSettingsLoading || isJwtSecretUpdateStatusLoading ? (
+ <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">
+ {isProjectSettingsLoading || isApiKeysEmpty
+ ? 'Retrieving API keys'
+ : 'JWT secret is being updated'}
+ </p>
+ </div>
+ ) : (
+ apiKeys.map((x, i: number) => (
+ <Panel.Content
+ key={x.api_key}
+ className={
+ i >= 1 &&
+ 'border-t border-panel-border-interior-light [[data-theme*=dark]_&]:border-panel-border-interior-dark'
}
- copy={canReadAPIKeys && isNotUpdatingJwtSecret}
- reveal={x.tags !== 'anon' && canReadAPIKeys && isNotUpdatingJwtSecret}
- value={
- !canReadAPIKeys
- ? 'You need additional permissions to view API keys'
- : jwtSecretUpdateStatus === JwtSecretUpdateStatus.Failed
- ? 'JWT secret update failed, new API key may have issues'
- : jwtSecretUpdateStatus === JwtSecretUpdateStatus.Updating
- ? 'Updating JWT secret...'
- : x?.api_key ?? 'You need additional permissions to view API keys'
- }
- onChange={() => {}}
- descriptionText={
- x.tags === 'service_role'
- ? 'This key has the ability to bypass Row Level Security. Never share it publicly.'
- : 'This key is safe to use in a browser if you have enabled Row Level Security for your tables and configured policies.'
- }
- />
- </Panel.Content>
- ))
- )}
- </Panel>
+ >
+ <Input
+ readOnly
+ disabled
+ layout="horizontal"
+ className="input-mono"
+ // @ts-ignore
+ label={
+ <>
+ {x.tags?.split(',').map((x, i: number) => (
+ <code key={`${x}${i}`} className="text-xs text-code">
+ {x}
+ </code>
+ ))}
+ {x.tags === 'service_role' && (
+ <>
+ <code className="bg-red-900 text-xs text-white">secret</code>
+ </>
+ )}
+ {x.tags === 'anon' && <code className="text-xs text-code">public</code>}
+ </>
+ }
+ copy={canReadAPIKeys && isNotUpdatingJwtSecret}
+ reveal={x.tags !== 'anon' && canReadAPIKeys && isNotUpdatingJwtSecret}
+ value={
+ !canReadAPIKeys
+ ? 'You need additional permissions to view API keys'
+ : jwtSecretUpdateStatus === JwtSecretUpdateStatus.Failed
+ ? 'JWT secret update failed, new API key may have issues'
+ : jwtSecretUpdateStatus === JwtSecretUpdateStatus.Updating
+ ? 'Updating JWT secret...'
+ : x?.api_key ?? 'You need additional permissions to view API keys'
+ }
+ onChange={() => {}}
+ descriptionText={
+ x.tags === 'service_role'
+ ? 'This key has the ability to bypass Row Level Security. Never share it publicly. ' +
+ (legacy ? 'Prefer using Publishable API keys instead.' : '')
+ : 'This key is safe to use in a browser if you have enabled Row Level Security for your tables and configured policies. ' +
+ (legacy ? 'Prefer using Secret API keys instead.' : '')
+ }
+ />
+ </Panel.Content>
+ ))
+ )}
+ <Panel.Notice
+ className="border-t"
+ title="New API keys coming Q4 2024"
+ description={`
+\`anon\` and \`service_role\` API keys will be changing to \`publishable\` and \`secret\` API keys.
+`}
+ href="https://github.com/orgs/supabase/discussions/29260"
+ buttonText="Read the announcement"
+ />
+ </Panel>
+ </>
)
}
export default DisplayApiSettings