mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem The database access preview still uses “Temporary access” across its settings and member rules. ## Solution Use “Database token access” for the feature and “Member access” for member rules. Update the preview, settings, dialogs, feedback, member status messages and docs together. Move the guide to `/guides/platform/token-access`, permanently redirect the old URL, and preserve existing section anchors. ## Review instructions 1. Open [the Studio preview](https://studio-staging-git-dnywh-database-token-access-naming-supabase.vercel.app), then Feature previews and find **Database token access**. Enable the preview for a supported project, then open [Database Settings](https://studio-staging-git-dnywh-database-token-access-naming-supabase.vercel.app/project/_/database/settings). 2. Check the **Database token access** heading, **Allow token access** switch and **Member access** table. Open **Add rule** and an existing rule to check the sheet titles. Open a rule’s delete confirmation and cancel it. 3. With an assigned role, check the access status above the member table. As a member without management permission, check the access notice uses the same feature name. 4. Open the [database token access guide in the docs preview](https://docs-git-dnywh-database-token-access-naming-supabase.vercel.app/docs/guides/platform/token-access). Check the guide and navigation use the new name, the dashboard instructions match Studio, and the existing section links from the member guide still work. Open `/docs/guides/platform/temporary-access` and its `.md` variant to check they permanently redirect to the new URLs. | Before | After | | --- | --- | | <img width="726" height="367" alt="CleanShot 2026-11-30 at 16 06 00" src="https://github.com/user-attachments/assets/be351f0c-d578-4289-8785-5c4e69a254a7" /> | <img width="729" height="374" alt="CleanShot 2026-11-30 at 16 05 38" src="https://github.com/user-attachments/assets/f02b470d-ef1a-4b6c-bdbb-20fe10b847c6" /> |
179 lines
5.8 KiB
TypeScript
179 lines
5.8 KiB
TypeScript
import { useParams } from 'common'
|
||
import dayjs from 'dayjs'
|
||
import { ChevronDownIcon } from 'lucide-react'
|
||
import { cn, Collapsible, CollapsibleContent, CollapsibleTrigger } from 'ui'
|
||
import { Admonition } from 'ui-patterns/Admonition'
|
||
import { TimestampInfo } from 'ui-patterns/TimestampInfo'
|
||
|
||
import { AlertError } from '@/components/ui/AlertError'
|
||
import {
|
||
JitDbAccessStatusData,
|
||
useJitDbAccessStatusQuery,
|
||
} from '@/data/jit-db-access/jit-db-access-status-query'
|
||
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
||
|
||
const ACCESS_TITLE = 'You can connect to this database using access tokens'
|
||
|
||
export const JitDbAccessInfo = () => {
|
||
const { ref: projectRef } = useParams()
|
||
const { data: jitDbAccess, error, isError } = useJitDbAccessStatusQuery({ projectRef })
|
||
|
||
const { can: canManageJitDbAccess } = useAsyncCheckPermissionsV2(
|
||
FGA_PERMISSIONS.PROJECT.DATABASE_JIT_WRITE
|
||
)
|
||
|
||
if (!jitDbAccess) return null
|
||
|
||
if (isError) {
|
||
return (
|
||
<AlertError
|
||
className="border-0 rounded-none"
|
||
subject="Failed to retrieve member access status"
|
||
error={error}
|
||
/>
|
||
)
|
||
} else if (jitDbAccess.user_id === undefined) {
|
||
if (!canManageJitDbAccess) return <NoAccess />
|
||
else return null
|
||
} else if (jitDbAccess.user_roles.length === 1) {
|
||
return <SingleRoleAccess role={jitDbAccess.user_roles[0]} />
|
||
} else {
|
||
return <MultiRoleAccess roles={jitDbAccess.user_roles} />
|
||
}
|
||
}
|
||
|
||
type JitRole = JitDbAccessStatusData['user_roles'][number]
|
||
|
||
// A role without `expires_at` never expires, so it keeps access alive. Units in unix seconds.
|
||
const isRoleExpired = (role: JitRole) =>
|
||
role.expires_at !== undefined && dayjs.unix(role.expires_at).isBefore(dayjs())
|
||
|
||
const SingleRoleAccess = ({ role }: { role: JitRole }) => {
|
||
const isExpired = isRoleExpired(role)
|
||
|
||
const { can: canManageJitDbAccess } = useAsyncCheckPermissionsV2(
|
||
FGA_PERMISSIONS.PROJECT.DATABASE_JIT_WRITE
|
||
)
|
||
|
||
if (isExpired) {
|
||
if (!canManageJitDbAccess) return <ExpiredAccess />
|
||
else return null
|
||
}
|
||
|
||
return (
|
||
<Admonition
|
||
type="default"
|
||
showIcon={false}
|
||
className={cn('rounded-none', canManageJitDbAccess ? 'border-x-0 border-t-0' : 'border-none')}
|
||
title={ACCESS_TITLE}
|
||
description={
|
||
<div className="flex items-center gap-x-2">
|
||
<span>
|
||
<span>As</span> <code>{role.role}</code>
|
||
</span>
|
||
{role.expires_at && (
|
||
<>
|
||
<span>·</span>
|
||
<span>
|
||
Expires on{' '}
|
||
<TimestampInfo className="text-sm" utcTimestamp={role.expires_at * 1000} />
|
||
</span>
|
||
</>
|
||
)}
|
||
</div>
|
||
}
|
||
/>
|
||
)
|
||
}
|
||
|
||
const MultiRoleAccess = ({ roles }: { roles: JitDbAccessStatusData['user_roles'] }) => {
|
||
// A role without `expires_at` never expires, so it keeps access alive
|
||
const isExpired = roles.length > 0 && roles.every(isRoleExpired)
|
||
|
||
// Earliest expiry among roles that are still active (unix seconds)
|
||
const upcomingExpiries = roles.flatMap((role) =>
|
||
role.expires_at !== undefined && !isRoleExpired(role) ? [role.expires_at] : []
|
||
)
|
||
const nextExpiry = upcomingExpiries.length > 0 ? Math.min(...upcomingExpiries) : undefined
|
||
|
||
const { can: canManageJitDbAccess } = useAsyncCheckPermissionsV2(
|
||
FGA_PERMISSIONS.PROJECT.DATABASE_JIT_WRITE
|
||
)
|
||
|
||
if (isExpired) {
|
||
if (!canManageJitDbAccess) return <ExpiredAccess />
|
||
else return null
|
||
}
|
||
|
||
return (
|
||
<Collapsible className={canManageJitDbAccess ? 'border-b' : ''}>
|
||
<CollapsibleTrigger
|
||
type="button"
|
||
className="flex items-center justify-between gap-x-2 w-full py-4 px-4 text-left cursor-pointer [&[data-state=open]>svg]:-rotate-180!"
|
||
>
|
||
<span className="block text-sm">
|
||
<span className="block mb-0.5">{ACCESS_TITLE}</span>
|
||
<span className="flex items-center gap-x-2 text-foreground-light">
|
||
<span>Assigned {roles.length} roles</span>
|
||
{nextExpiry !== undefined && (
|
||
<>
|
||
<span>·</span>
|
||
<span>
|
||
<span>Next expiry on</span>{' '}
|
||
<TimestampInfo className="text-sm" utcTimestamp={nextExpiry * 1000} />
|
||
</span>
|
||
</>
|
||
)}
|
||
</span>
|
||
</span>
|
||
<ChevronDownIcon className="transition-transform" size={14} />
|
||
</CollapsibleTrigger>
|
||
<CollapsibleContent className="data-closed:animate-collapsible-up-clipped data-open:animate-collapsible-down-clipped motion-reduce:animate-none">
|
||
{roles.map((role) => {
|
||
return (
|
||
<div key={role.role} className="py-2 px-4 first:pt-0 text-foreground-light">
|
||
<p className="text-sm flex items-center gap-x-2">
|
||
<code>{role.role}</code>
|
||
<span>·</span>
|
||
{role.expires_at && (
|
||
<span>
|
||
Expires on{' '}
|
||
<TimestampInfo className="text-sm" utcTimestamp={role.expires_at * 1000} />
|
||
</span>
|
||
)}
|
||
</p>
|
||
</div>
|
||
)
|
||
})}
|
||
</CollapsibleContent>
|
||
</Collapsible>
|
||
)
|
||
}
|
||
|
||
const ExpiredAccess = () => {
|
||
const { can: canManageJitDbAccess } = useAsyncCheckPermissionsV2(
|
||
FGA_PERMISSIONS.PROJECT.DATABASE_JIT_WRITE
|
||
)
|
||
|
||
return (
|
||
<Admonition
|
||
type="default"
|
||
className={cn('rounded-none', canManageJitDbAccess ? 'border-x-0 border-t-0' : 'border-none')}
|
||
title="Your database token access has expired"
|
||
description="Contact your project’s owner or administrator to renew your access."
|
||
/>
|
||
)
|
||
}
|
||
|
||
const NoAccess = () => {
|
||
return (
|
||
<Admonition
|
||
type="default"
|
||
showIcon={false}
|
||
className="rounded-none border-none"
|
||
title="You don’t have database token access"
|
||
description="Contact your project’s owner or administrator to request access."
|
||
/>
|
||
)
|
||
}
|