MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / ApiKeysSection

Function ApiKeysSection

web/src/app/profile/components/api-keys-section.tsx:50–372  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

48}
49
50export function ApiKeysSection() {
51 const { toast } = useToast()
52 const queryClient = useQueryClient()
53
54 const {
55 data: tokensData,
56 isLoading: loadingTokens,
57 error: tokensError,
58 refetch: refetchTokens,
59 isFetching: fetchingTokens,
60 } = useQuery({
61 queryKey: ['personal-access-tokens'],
62 queryFn: fetchTokens,
63 })
64
65 // Filter tokens to only show PATs (not CLI sessions)
66 const tokens = (tokensData?.tokens ?? []).filter(
67 (token) => token.type === 'pat',
68 )
69
70 const [createTokenOpen, setCreateTokenOpen] = useState(false)
71 const [tokenName, setTokenName] = useState('')
72 const [expiresInDays, setExpiresInDays] = useState(365)
73 const [newTokenValue, setNewTokenValue] = useState('')
74 const [showTokenValue, setShowTokenValue] = useState(false)
75 const [copiedTokenId, setCopiedTokenId] = useState<string | null>(null)
76 const [revokeDialogOpen, setRevokeDialogOpen] = useState(false)
77 const [tokenToRevoke, setTokenToRevoke] = useState<string | null>(null)
78
79 const createTokenMutation = useMutation({
80 mutationFn: async ({
81 name,
82 expiresInDays,
83 }: {
84 name?: string
85 expiresInDays: number
86 }) => {
87 const res = await fetch('/api/api-keys', {
88 method: 'POST',
89 headers: { 'Content-Type': 'application/json' },
90 body: JSON.stringify({ name, expiresInDays }),
91 })
92 if (!res.ok) {
93 const errorText = await res.text()
94 throw new Error(errorText)
95 }
96 return res.json()
97 },
98 onSuccess: async (data) => {
99 await queryClient.invalidateQueries({
100 queryKey: ['personal-access-tokens'],
101 })
102 setNewTokenValue(data.token)
103 setShowTokenValue(true)
104 toast({ title: 'API Key created' })
105 },
106 onError: (e: any) => {
107 toast({

Callers

nothing calls this directly

Calls 6

useToastFunction · 0.90
toastFunction · 0.85
setTimeoutFunction · 0.85
openRevokeDialogFunction · 0.85
copyToClipboardFunction · 0.70
fetchFunction · 0.50

Tested by

no test coverage detected