Files
supabase/apps/studio/components/interfaces/Settings/API/ServiceList.tsx
T
Stojan DimitrovskiandIvan Vasilov 4945ba1861 feat: add asymmetric JWT UI (#36519)
* original files from previous PR

* get rid of router in jwt-secrets to make it show up

* rename jwt-secrets page to jwt-signing-keys

* add jwt-signing-keys query

* add legacy jwt signing keys query

* wire-up JwtSecretKeysTable with queries

* add jwt signing keys page to settings menu

* deduplicate labels, descriptions, etc

* add create, update jwt-signing-key mutations

* update types

* remove unused components, to be refactored later

* make everything into a mostly working state

* legacy migration added

* put jwt keys page like api keys

* fully migrate legacy jwt secret page

* fix prettier

* fix typecheck ts-expect-error

* rm unneeded file

* Fix compile errors.

* Rename the files and move them to the same folder.

* Merge the two constant files.

* Fix the imports.

* Fix a bug in the API keys page when opening it in a new tab.

* Change the page to be at /signing-keys

* Fix some minor types.

* Break apart some of the components in the signing keys UI.

* Use a feature banner for the initial action.

* Make a create key dialog and move functionality there.

* Fix some cosmetic issues.

* Minor cosmetic fixes.

* Remove extra keys in RQ cache.

* Add a missing link

* Add a banner when the feature flag is false.

* Minor type fix.

* more tiny type fix

* fix error on create standby key

* add alert to prevent revoking legacy jwt secret without disabling legacy api keys first

---------

Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2025-06-23 09:36:07 +12:00

123 lines
4.7 KiB
TypeScript

import { useQueryClient } from '@tanstack/react-query'
import { AlertCircle } from 'lucide-react'
import { useEffect, useRef } from 'react'
import { toast } from 'sonner'
import { useParams } from 'common'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import DatabaseSelector from 'components/ui/DatabaseSelector'
import Panel from 'components/ui/Panel'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { configKeys } from 'data/config/keys'
import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query'
import { useLoadBalancersQuery } from 'data/read-replicas/load-balancers-query'
import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
import { PROJECT_STATUS } from 'lib/constants'
import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'
import { Badge, Input } from 'ui'
import { ApiKeysMoved } from './ApiKeysMoved'
import { PostgrestConfig } from './PostgrestConfig'
const ServiceList = () => {
const client = useQueryClient()
const { project, isLoading } = useProjectContext()
const { ref: projectRef, source } = useParams()
const state = useDatabaseSelectorStateSnapshot()
const { data: customDomainData } = useCustomDomainsQuery({ projectRef })
const { data: databases, isError } = useReadReplicasQuery({ projectRef })
const { data: loadBalancers } = useLoadBalancersQuery({ projectRef })
// Get the API service
const isCustomDomainActive = customDomainData?.customDomain?.status === 'active'
const selectedDatabase = databases?.find((db) => db.identifier === state.selectedDatabaseId)
const loadBalancerSelected = state.selectedDatabaseId === 'load-balancer'
const replicaSelected = selectedDatabase?.identifier !== projectRef
const endpoint =
isCustomDomainActive && state.selectedDatabaseId === projectRef
? `https://${customDomainData.customDomain.hostname}`
: loadBalancerSelected
? loadBalancers?.[0].endpoint ?? ''
: selectedDatabase?.restUrl
return (
<div>
{isLoading ? (
<GenericSkeletonLoader />
) : project?.status !== PROJECT_STATUS.ACTIVE_HEALTHY ? (
<div className="flex items-center justify-center rounded border border-overlay bg-surface-100 p-8">
<AlertCircle size={16} />
<p className="text-sm text-foreground-light ml-2">
API settings are unavailable as the project is not active
</p>
</div>
) : (
<>
<section>
<Panel
title={
<div className="w-full flex items-center justify-between">
<h5 className="mb-0">Project URL</h5>
<DatabaseSelector
additionalOptions={
(loadBalancers ?? []).length > 0
? [{ id: 'load-balancer', name: 'API Load Balancer' }]
: []
}
/>
</div>
}
>
<Panel.Content>
{isError ? (
<div className="flex items-center justify-center py-4 space-x-2">
<AlertCircle size={16} />
<p className="text-sm text-foreground-light">Failed to retrieve project URL</p>
</div>
) : (
<Input
copy
label={
isCustomDomainActive ? (
<div className="flex items-center space-x-2">
<p>URL</p>
<Badge>Custom domain active</Badge>
</div>
) : (
'URL'
)
}
readOnly
disabled
className="input-mono"
value={endpoint}
descriptionText={
loadBalancerSelected
? 'RESTful endpoint for querying and managing your databases through your load balancer'
: replicaSelected
? 'RESTful endpoint for querying your read replica'
: 'RESTful endpoint for querying and managing your database'
}
layout="horizontal"
/>
)}
</Panel.Content>
</Panel>
</section>
<section className="mb-8">
<ApiKeysMoved />
</section>
<section id="postgrest-config">
<PostgrestConfig />
</section>
</>
)}
</div>
)
}
export default ServiceList