ApiKeysTabContent.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { PermissionAction } from '@supabase/shared-types/out/constants'
  2. import { useParams } from 'common'
  3. import { AlertCircle, ExternalLink, Loader2 } from 'lucide-react'
  4. import Link from 'next/link'
  5. import type { ReactNode } from 'react'
  6. import { Button } from 'ui'
  7. import { Input } from 'ui-patterns/DataInputs/Input'
  8. import type { projectKeys } from './Connect.types'
  9. import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
  10. function KeyRow({ label, value }: { label: ReactNode; value: string }) {
  11. return (
  12. <div className="flex flex-col gap-5 lg:grid lg:grid-cols-12">
  13. <div className="col-span-4">
  14. <h3 className="text-sm text-foreground">{label}</h3>
  15. </div>
  16. <div className="col-span-8">
  17. <Input readOnly copy className="font-mono" value={value} />
  18. </div>
  19. </div>
  20. )
  21. }
  22. export function ApiKeysTabContent({ projectKeys }: { projectKeys: projectKeys }) {
  23. const { ref: projectRef } = useParams()
  24. const { isLoading: isLoadingPermissions, can: canReadAPIKeys } = useAsyncCheckPermissions(
  25. PermissionAction.SECRETS_READ,
  26. '*'
  27. )
  28. if (isLoadingPermissions) {
  29. return (
  30. <div className="flex items-center justify-center py-8 space-x-2">
  31. <Loader2 className="animate-spin" size={16} strokeWidth={1.5} />
  32. <p className="text-sm text-foreground-light">Retrieving API keys</p>
  33. </div>
  34. )
  35. }
  36. if (!canReadAPIKeys) {
  37. return (
  38. <div className="flex items-center py-8 space-x-2">
  39. <AlertCircle size={16} strokeWidth={1.5} />
  40. <p className="text-sm text-foreground-light">You don't have permission to view API keys.</p>
  41. </div>
  42. )
  43. }
  44. return (
  45. <div className="flex flex-col gap-8">
  46. <KeyRow label="Project URL" value={projectKeys.apiUrl ?? ''} />
  47. <KeyRow label="Publishable Key" value={projectKeys.publishableKey ?? ''} />
  48. <KeyRow
  49. label={
  50. <>
  51. Anon Key <span className="text-foreground-lighter font-normal">(Legacy)</span>
  52. </>
  53. }
  54. value={projectKeys.anonKey ?? ''}
  55. />
  56. <div className="gap-5 lg:grid lg:grid-cols-12">
  57. <div className="col-start-5 col-span-8 pl-2 flex items-center justify-between">
  58. <p className="text-xs text-foreground-lighter">For secret keys, see API settings.</p>
  59. <Button asChild type="default" icon={<ExternalLink size={14} />}>
  60. <Link href={`/project/${projectRef}/settings/api-keys`}>API settings</Link>
  61. </Button>
  62. </div>
  63. </div>
  64. </div>
  65. )
  66. }