mirror of
https://github.com/supabase/supabase.git
synced 2026-07-04 02:54:28 +08:00
* Bump the deps, refactor deprecated code.
* Migrate keepPreviousData usage.
* Migrate all uses of InfiniteQuery.
* Fix refetchInterval in queries.
* Migrate all use of isLoading to isPending in mutations.
* Fix accessing location in claim-project.
* Fix a bug in duplicate query keys.
* Migrate all queries to use isPending.
* Revert "Fix accessing location in claim-project."
This reverts commit 2a07df64b5.
* Revert the rss.xml file to master.
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useMemo } from 'react'
|
|
|
|
import { useParams } from 'common'
|
|
import { useAPIKeysQuery } from 'data/api-keys/api-keys-query'
|
|
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
|
|
|
|
interface ApiKeysVisibilityState {
|
|
hasApiKeys: boolean
|
|
isLoading: boolean
|
|
canReadAPIKeys: boolean
|
|
canInitApiKeys: boolean
|
|
shouldDisableUI: boolean
|
|
}
|
|
|
|
/**
|
|
* A hook that provides visibility states for API keys UI components
|
|
* Consolidates logic for determining access to API keys functionality
|
|
*/
|
|
export function useApiKeysVisibility(): ApiKeysVisibilityState {
|
|
const { ref: projectRef } = useParams()
|
|
const { can: canReadAPIKeys, isLoading: isLoadingPermissions } = useAsyncCheckPermissions(
|
|
PermissionAction.SECRETS_READ,
|
|
'*'
|
|
)
|
|
|
|
const { data: apiKeysData, isPending: isLoadingApiKeys } = useAPIKeysQuery(
|
|
{
|
|
projectRef,
|
|
reveal: false,
|
|
},
|
|
{ enabled: canReadAPIKeys }
|
|
)
|
|
|
|
const publishableApiKeys = useMemo(
|
|
() => apiKeysData?.filter(({ type }) => type === 'publishable') ?? [],
|
|
[apiKeysData]
|
|
)
|
|
|
|
// Check if there are any publishable API keys
|
|
// we don't check for secret keys because they can be optionally deleted
|
|
const hasApiKeys = publishableApiKeys.length > 0
|
|
|
|
// Can initialize API keys when in rollout, has permissions, not loading, and no API keys yet
|
|
const canInitApiKeys = canReadAPIKeys && !isLoadingApiKeys && !hasApiKeys
|
|
|
|
// Disable UI for publishable keys and secrets keys if flag is not enabled OR no API keys created yet
|
|
const shouldDisableUI = !hasApiKeys
|
|
|
|
return {
|
|
hasApiKeys,
|
|
isLoading: isLoadingPermissions || (canReadAPIKeys && isLoadingApiKeys),
|
|
canReadAPIKeys,
|
|
canInitApiKeys,
|
|
shouldDisableUI,
|
|
}
|
|
}
|