Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 470
chore(clerk-js): Remove secret key column in API keys component#7107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
5a9b90619a80856587f25de27fdb48d7896817b8b535016e7b4a8f1c0407380c68a03b996c57951e5a684fb8000def59445ec60e903a365117bbb98d6fa9bcca408959209f76a0838b1be632c4b5254e84aeab7bb0d3251702f5a9c43295b6fceef49b30479f352921f223828f7f4549e8992ae6537f6e020398fFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@clerk/localizations": minor | ||
| --- | ||
| Added localization entry for the API key copy modal component. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@clerk/clerk-js": minor | ||
| --- | ||
| Replaced the persistent key column in the API keys table with a one-time modal that displays the secret immediately after creation. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import React from 'react'; | ||
| import { Modal } from '@/ui/elements/Modal'; | ||
| import type { ThemableCssProp } from '@/ui/styledSystem'; | ||
| type ApiKeyModalProps = React.ComponentProps<typeof Modal> & { | ||
| modalRoot?: React.MutableRefObject<HTMLElement | null>; | ||
| }; | ||
| /** | ||
| * Container styles for modals rendered within a custom portal root (e.g., UserProfile or OrganizationProfile). | ||
| * When a modalRoot is provided, the modal is scoped to that container rather than the document root, | ||
| * requiring different positioning (absolute instead of fixed) and backdrop styling. | ||
| */ | ||
| const getScopedPortalContainerStyles = (modalRoot?: React.MutableRefObject<HTMLElement | null>): ThemableCssProp => { | ||
| return [ | ||
| { alignItems: 'center' }, | ||
| modalRoot | ||
| ? t => ({ | ||
| position: 'absolute', | ||
| right: 0, | ||
| bottom: 0, | ||
| backgroundColor: 'inherit', | ||
| backdropFilter: `blur(${t.sizes.$2})`, | ||
| display: 'flex', | ||
| justifyContent: 'center', | ||
| minHeight: '100%', | ||
| height: '100%', | ||
| width: '100%', | ||
| borderRadius: t.radii.$lg, | ||
| }) | ||
| : {}, | ||
| ]; | ||
| }; | ||
| export const ApiKeyModal = ({ modalRoot, containerSx, ...modalProps }: ApiKeyModalProps) => { | ||
| return ( | ||
| <Modal | ||
| {...modalProps} | ||
| portalRoot={modalRoot} | ||
| containerSx={[getScopedPortalContainerStyles(modalRoot), containerSx]} | ||
| /> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2,6 +2,7 @@ import { isClerkAPIResponseError } from '@clerk/shared/error'; | ||
| import { useClerk, useOrganization, useUser } from '@clerk/shared/react'; | ||
| import type { CreateAPIKeyParams } from '@clerk/shared/types'; | ||
| import { lazy, useState } from 'react'; | ||
| import { useSWRConfig } from 'swr'; | ||
| import useSWRMutation from 'swr/mutation'; | ||
| import { useProtect } from '@/ui/common'; | ||
| @@ -42,6 +43,12 @@ const RevokeAPIKeyConfirmationModal = lazy(() => | ||
| })), | ||
| ); | ||
| const CopyApiKeyModal = lazy(() => | ||
| import(/* webpackChunkName: "copy-api-key-modal"*/ './CopyApiKeyModal').then(module => ({ | ||
| default: module.CopyApiKeyModal, | ||
| })), | ||
| ); | ||
| export const APIKeysPage = ({ subject, perPage, revokeModalRoot }: APIKeysPageProps) => { | ||
| const isOrg = isOrganizationId(subject); | ||
| const canReadAPIKeys = useProtect({ permission: 'org:sys_api_keys:read' }); | ||
| @@ -61,23 +68,34 @@ export const APIKeysPage = ({ subject, perPage, revokeModalRoot }: APIKeysPagePr | ||
| cacheKey, | ||
| } = useApiKeys({ subject, perPage, enabled: isOrg ? canReadAPIKeys : true }); | ||
| const card = useCardState(); | ||
| const { trigger: createApiKey, isMutating } = useSWRMutation(cacheKey, (_, { arg }: { arg: CreateAPIKeyParams }) => | ||
| clerk.apiKeys.create(arg), | ||
| const clerk = useClerk(); | ||
| const { | ||
| data: createdApiKey, | ||
| trigger: createApiKey, | ||
| isMutating, | ||
| } = useSWRMutation( | ||
| { | ||
| ...cacheKey, | ||
| action: 'create', | ||
| }, | ||
| (_key, { arg }: { arg: CreateAPIKeyParams }) => clerk.apiKeys.create(arg), | ||
| ); | ||
| const { mutate: mutateApiKeys } = useSWRConfig(); | ||
| const { t } = useLocalizations(); | ||
coderabbitai[bot] marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const clerk = useClerk(); | ||
| const [isRevokeModalOpen, setIsRevokeModalOpen] = useState(false); | ||
| const [selectedApiKeyId, setSelectedApiKeyId] = useState(''); | ||
| const [selectedApiKeyName, setSelectedApiKeyName] = useState(''); | ||
| const [isCopyModalOpen, setIsCopyModalOpen] = useState(false); | ||
| const handleCreateApiKey = async (params: OnCreateParams, closeCardFn: () => void) => { | ||
| const handleCreateApiKey = async (params: OnCreateParams) => { | ||
| try { | ||
| await createApiKey({ | ||
| ...params, | ||
| subject, | ||
| }); | ||
| closeCardFn(); | ||
| void mutateApiKeys(cacheKey); | ||
| card.setError(undefined); | ||
| setIsCopyModalOpen(true); | ||
| } catch (err: any) { | ||
Comment on lines
+90
to
99
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't open the copy modal before the new secret exists After - await createApiKey({+ const created = await createApiKey({
...params,
subject,
});
- void mutateApiKeys(cacheKey);- card.setError(undefined);- setIsCopyModalOpen(true);+ void mutateApiKeys(cacheKey);+ card.setError(undefined);+ if (created?.secret) {+ setLatestCreatedApiKey(created);+ setIsCopyModalOpen(true);+ }Add a
🤖 Prompt for AI Agents | ||
| if (isClerkAPIResponseError(err)) { | ||
| if (err.status === 409) { | ||
| @@ -147,7 +165,17 @@ export const APIKeysPage = ({ subject, perPage, revokeModalRoot }: APIKeysPagePr | ||
| </Action.Card> | ||
| </Flex> | ||
| </Action.Open> | ||
| <CopyApiKeyModal | ||
| isOpen={isCopyModalOpen} | ||
| onOpen={() => setIsCopyModalOpen(true)} | ||
| onClose={() => setIsCopyModalOpen(false)} | ||
| apiKeyName={createdApiKey?.name ?? ''} | ||
| apiKeySecret={createdApiKey?.secret ?? ''} | ||
| modalRoot={revokeModalRoot} | ||
| /> | ||
| </Action.Root> | ||
| <ApiKeysTable | ||
| rows={apiKeys} | ||
| isLoading={isLoading} | ||
| @@ -164,6 +192,8 @@ export const APIKeysPage = ({ subject, perPage, revokeModalRoot }: APIKeysPagePr | ||
| rowInfo={{ allRowsCount: itemCount, startingRow, endingRow }} | ||
| /> | ||
| )} | ||
| {/* Modals */} | ||
| <RevokeAPIKeyConfirmationModal | ||
| subject={subject} | ||
| isOpen={isRevokeModalOpen} | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.