Files
supabase/apps/studio/components/layouts/WorkersLayout/WorkersLayout.tsx
Jordi Enric b885b69bff feat(studio): restore workers secrets page FE-4280 (#49762)
## Problem

Workers Secrets was merged in #49589 into the stacked
jordi/workers-detail branch. The parent Workers PR reached master
without that child merge, leaving the page absent from staging.

## Fix

Cherry-pick the missing Workers Secrets route, menu item, shared-secret
copy, and generated route tree onto current master. The page uses the
existing workers flag and permission gates.

## How to test

- Enable the workers flag for a project with Workers access.
- Open Workers, then select Secrets.
- Expected result: the shared project secrets page renders at
/project/:ref/workers/secrets and is not treated as a worker named
secrets.
- Add, edit, or delete a secret, then confirm the same value appears
under Edge Functions, Secrets.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
  * Added a **Secrets** page to the Workers section.
  * Added navigation to Worker secrets from the Workers menu.
* Displayed default secrets and deployment-specific guidance where
applicable.
* Clarified that platform secrets are shared between Edge Functions and
Workers.
  * Updated deletion warnings to reflect shared secret usage.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-31 19:17:39 +00:00

101 lines
3.0 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { FeatureFlagContext, useFlag, useParams } from 'common'
import { useRouter } from 'next/router'
import { useContext, useEffect, useMemo, type PropsWithChildren } from 'react'
import { Badge } from 'ui'
import { ProjectLayout } from '../ProjectLayout'
import { NoPermission } from '@/components/ui/NoPermission'
import { ProductMenu } from '@/components/ui/ProductMenu'
import type { ProductMenuGroup } from '@/components/ui/ProductMenu/ProductMenu.types'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
import { withAuth } from '@/hooks/misc/withAuth'
import { PRODUCT_NAME } from '@/lib/constants/workers'
const useGenerateWorkersMenu = (): ProductMenuGroup[] => {
const { ref: projectRef = 'default' } = useParams()
return useMemo(
() => [
{
title: 'Manage',
items: [
{
name: PRODUCT_NAME,
key: 'main',
pages: ['', '[name]'],
url: `/project/${projectRef}/workers`,
items: [],
},
{
name: 'Secrets',
key: 'secrets',
url: `/project/${projectRef}/workers/secrets`,
items: [],
},
],
},
],
[projectRef]
)
}
export const WorkersProductMenu = () => {
const router = useRouter()
const page = router.pathname.split('/')[4]
const menu = useGenerateWorkersMenu()
return <ProductMenu page={page} menu={menu} />
}
interface WorkersLayoutProps {
title?: string
}
const WorkersLayoutContent = ({ children, title }: PropsWithChildren<WorkersLayoutProps>) => {
const router = useRouter()
const { ref: projectRef } = useParams()
const { hasLoaded } = useContext(FeatureFlagContext)
const workersEnabled = useFlag('workers')
// The v2 workers routes require the FGA workers_read permission, which shared-types does not
// expose yet; they reuse the Edge Functions OAuth scope, so gate on the same product here.
const { isLoading: isLoadingPermissions, can: canReadWorkers } = useAsyncCheckPermissions(
PermissionAction.FUNCTIONS_READ,
'*'
)
useEffect(() => {
if (hasLoaded && !workersEnabled) {
router.replace(`/project/${projectRef}`)
}
}, [router, hasLoaded, workersEnabled, projectRef])
if (!workersEnabled) return null
if (isLoadingPermissions) {
return (
<ProjectLayout
isLoading
product={PRODUCT_NAME}
browserTitle={{ entity: PRODUCT_NAME, section: title }}
/>
)
}
return (
<ProjectLayout
product={PRODUCT_NAME}
productMenuBadge={<Badge variant="warning">Private Alpha</Badge>}
productMenu={<WorkersProductMenu />}
isBlocking={false}
browserTitle={{ entity: PRODUCT_NAME, section: title }}
>
{canReadWorkers ? (
children
) : (
<NoPermission isFullPage resourceText="view this project's workers" />
)}
</ProjectLayout>
)
}
export const WorkersLayout = withAuth(WorkersLayoutContent)