-
Notifications
You must be signed in to change notification settings - Fork 402
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
base: main
Are you sure you want to change the base?
Changes from all commits
5a9b906
19a8085
6587f25
de27fdb
48d7896
817b8b5
35016e7
b4a8f1c
0407380
c68a03b
996c579
51e5a68
4fb8000
def5944
5ec60e9
03a3651
17bbb98
d6fa9bc
ca40895
9209f76
a0838b1
be632c4
b5254e8
4aeab7b
b0d3251
702f5a9
c43295b
File filter
Filter by extension
Conversations
Jump to
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 |
|---|---|---|
|
|
@@ -42,6 +42,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 +67,26 @@ 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 { t } = useLocalizations(); | ||
| const clerk = useClerk(); | ||
| const { | ||
| data: createdApiKey, | ||
| trigger: createApiKey, | ||
| isMutating, | ||
| } = useSWRMutation(cacheKey, (_key, { arg }: { arg: CreateAPIKeyParams }) => clerk.apiKeys.create(arg)); | ||
| const { t } = useLocalizations(); | ||
|
Comment on lines
+71
to
+76
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. 🛠️ Refactor suggestion | 🟠 Major Avoid reusing the list cache key for mutation; revalidate list after create Using Apply: +import { useSWRConfig } from 'swr';
@@
export const APIKeysPage = ({ subject, perPage, revokeModalRoot }: APIKeysPageProps) => {
@@
- const {
+ const {
data: createdApiKey,
trigger: createApiKey,
isMutating,
- } = useSWRMutation(cacheKey, (_key, { arg }: { arg: CreateAPIKeyParams }) => clerk.apiKeys.create(arg));
+ } = useSWRMutation(
+ `${cacheKey}-create`,
+ (_key, { arg }: { arg: CreateAPIKeyParams }) => clerk.apiKeys.create(arg),
+ );
+ const { mutate } = useSWRConfig();
@@
const handleCreateApiKey = async (params: OnCreateParams, closeCardFn: () => void) => {
try {
- await createApiKey({
+ await createApiKey({
...params,
subject,
});
+ // refresh list
+ await mutate(cacheKey);
closeCardFn();
card.setError(undefined);
setShowCopyAlert(true);
🤖 Prompt for AI Agents |
||
| 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(); | ||
| card.setError(undefined); | ||
| setIsCopyModalOpen(true); | ||
| } catch (err: any) { | ||
| if (isClerkAPIResponseError(err)) { | ||
| if (err.status === 409) { | ||
|
|
@@ -147,7 +156,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 +183,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.