-
Notifications
You must be signed in to change notification settings - Fork 419
fix(shared): Explicitly pass subject parameter to API keys fetcher hook #7344
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
Conversation
🦋 Changeset detectedLatest commit: 8aa2d9b The changes in this PR will be included in the next version bump. This PR includes changesets to release 22 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughAdds two integration tests verifying API key subject selection, adds a user-profile page-object method to switch to the API Keys tab, and updates useAPIKeys hooks to forward the user subject into Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/elements
@clerk/clerk-expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/clerk-react
@clerk/react-router
@clerk/remix
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/themes
@clerk/types
@clerk/upgrade
@clerk/vue
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (4)
packages/shared/src/types/clerk.ts (1)
2004-2007: InternalsubjectonAPIKeysPropsis type‑correct but slightly leakyThe new
subject?: stringfield aligns with context usage, but it now appears on a public props type. If this is truly internal, consider either:
- Moving it to an internal context type instead of
APIKeysProps, or- Prefixing it (e.g.
__internal_subject) and adding a short doc sentence explaining it is not for app developers.This would reduce the chance of external code relying on it.
As per coding guidelines, keeping the public API surface minimal and clearly documented helps avoid accidental reliance on internal fields.
packages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsx (1)
31-36: UserProfile now correctly forces user ID as subjectPassing
subject: user.idthrough context ensures the user’s ID is authoritative for user‑profile API keys, even when an organization is active. That matches the intended behavior and permission checks.For consistency with
OrganizationAPIKeysPage, you might optionally reorder the value to:- <APIKeysContext.Provider value={{ componentName: 'APIKeys', ...apiKeysProps, subject: user.id }}> + <APIKeysContext.Provider value={{ ...apiKeysProps, componentName: 'APIKeys', subject: user.id }}>so internal fields always override any matching keys on
apiKeysProps.packages/clerk-js/src/ui/components/APIKeys/APIKeys.tsx (1)
245-258: Context‑first subject resolution matches the new contractUsing
ctx.subject ?? organizationCtx?.organization?.id ?? user?.id ?? ''correctly:
- Lets UserProfile/OrganizationProfile override via context,
- Falls back to active organization, then user,
- Keeps existing permission gating via
isOrganizationId(subject)aligned with the actual subject.You may optionally add a defensive assertion/log if
subjectends up as''(shouldn’t happen withwithCoreUserGuardand an active org/user) to surface misconfigurations earlier.As per coding guidelines, adding lightweight diagnostics around unexpected states can improve debuggability without changing behavior.
integration/tests/machine-auth/component.test.ts (1)
288-321: Avoid race by waiting for the API keys response before assertingcapturedSubjectThe new test correctly validates that UserProfile API keys use the user ID even with an active org, but there’s a timing risk:
expect(capturedSubject)can run before the first/api_keysrequest completes and before the route handler assignscapturedSubject, leading to intermittent failures.You can make this deterministic by waiting for the relevant response after switching to the API Keys tab:
await u.po.userProfile.waitForMounted(); - await u.po.userProfile.switchToAPIKeysTab(); - - // Verify the subject parameter is the user ID, not the organization ID - expect(capturedSubject).toBe(userId); + await u.po.userProfile.switchToAPIKeysTab(); + + // Ensure the API keys request has completed so capturedSubject is populated + await page.waitForResponse( + response => response.url().includes('/api_keys') && response.request().method() === 'GET', + ); + + // Verify the subject parameter is the user ID, not the organization ID + expect(capturedSubject).toBe(userId); expect(capturedSubject).not.toBe(fakeOrganization.organization.id);This matches how other tests in this file synchronize on network events and should eliminate flakiness.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (6)
integration/tests/machine-auth/component.test.ts(1 hunks)packages/clerk-js/src/ui/components/APIKeys/APIKeys.tsx(1 hunks)packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsx(1 hunks)packages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsx(1 hunks)packages/shared/src/types/clerk.ts(1 hunks)packages/testing/src/playwright/unstable/page-objects/userProfile.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (13)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
All code must pass ESLint checks with the project's configuration
Files:
integration/tests/machine-auth/component.test.tspackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsxpackages/testing/src/playwright/unstable/page-objects/userProfile.tspackages/clerk-js/src/ui/components/APIKeys/APIKeys.tsxpackages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsxpackages/shared/src/types/clerk.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
integration/tests/machine-auth/component.test.tspackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsxpackages/testing/src/playwright/unstable/page-objects/userProfile.tspackages/clerk-js/src/ui/components/APIKeys/APIKeys.tsxpackages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsxpackages/shared/src/types/clerk.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Follow established naming conventions (PascalCase for components, camelCase for variables)
Prefer importing types from
@clerk/shared/typesinstead of the deprecated@clerk/typesalias
Files:
integration/tests/machine-auth/component.test.tspackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsxpackages/testing/src/playwright/unstable/page-objects/userProfile.tspackages/clerk-js/src/ui/components/APIKeys/APIKeys.tsxpackages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsxpackages/shared/src/types/clerk.ts
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{test,spec}.{ts,tsx,js,jsx}: Unit tests are required for all new functionality
Verify proper error handling and edge cases
Include tests for all new features
Files:
integration/tests/machine-auth/component.test.ts
**/*.ts?(x)
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
Files:
integration/tests/machine-auth/component.test.tspackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsxpackages/testing/src/playwright/unstable/page-objects/userProfile.tspackages/clerk-js/src/ui/components/APIKeys/APIKeys.tsxpackages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsxpackages/shared/src/types/clerk.ts
**/*.{test,spec,e2e}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use real Clerk instances for integration tests
Files:
integration/tests/machine-auth/component.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Implement type guards forunknowntypes using the patternfunction isType(value: unknown): value is Type
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details in classes
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like<T extends { id: string }>
Use utility types likeOmit,Partial, andPickfor data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Useconst assertionswithas constfor literal types
Usesatisfiesoperator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...
Files:
integration/tests/machine-auth/component.test.tspackages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsxpackages/testing/src/playwright/unstable/page-objects/userProfile.tspackages/clerk-js/src/ui/components/APIKeys/APIKeys.tsxpackages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsxpackages/shared/src/types/clerk.ts
packages/clerk-js/src/ui/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/clerk-js-ui.mdc)
packages/clerk-js/src/ui/**/*.{ts,tsx}: Element descriptors should be written in camelCase
Use useCardState for card-level state management
Use useFormState for form-level state management
Use useLoadingStatus for managing loading states
Use useFormControl hook for form field state management with validation and localization support
All rendered values must be localized using useLocalizations hook - hard coded values are not allowed
Use localizationKeys for translating UI text with support for parameters and error messages
Use handleError utility for API error handling and provide field states for proper error mapping
Use the styled system sx prop with theme tokens for custom styling instead of inline styles
Use the Card component pattern with Card.Root, Card.Header, Card.Title, Card.Content, and Card.Footer for consistent card layouts
Use FormContainer with headerTitle and headerSubtitle localization keys combined with Form.Root and FormButtons for consistent form layouts
When form submission occurs, manage loading and error states by calling status.setLoading(), card.setLoading(), and card.setError() appropriately
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsxpackages/clerk-js/src/ui/components/APIKeys/APIKeys.tsxpackages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsx
packages/**/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsxpackages/testing/src/playwright/unstable/page-objects/userProfile.tspackages/clerk-js/src/ui/components/APIKeys/APIKeys.tsxpackages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsxpackages/shared/src/types/clerk.ts
packages/**/src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Implement proper logging with different levels
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsxpackages/testing/src/playwright/unstable/page-objects/userProfile.tspackages/clerk-js/src/ui/components/APIKeys/APIKeys.tsxpackages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsxpackages/shared/src/types/clerk.ts
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.tsx: Use error boundaries in React components
Minimize re-renders in React components
**/*.tsx: Use proper type definitions for props and state in React components
Leverage TypeScript's type inference where possible in React components
Use proper event types for handlers in React components
Implement proper generic types for reusable React components
Use proper type guards for conditional rendering in React components
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsxpackages/clerk-js/src/ui/components/APIKeys/APIKeys.tsxpackages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsx
**/*.{md,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Update documentation for API changes
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsxpackages/clerk-js/src/ui/components/APIKeys/APIKeys.tsxpackages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsx
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components (e.g.,UserProfile,NavigationMenu)
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Separate UI components from business logic components
Use useState for simple state management in React components
Use useReducer for complex state logic in React components
Implement proper state initialization in React components
Use proper state updates with callbacks in React components
Implement proper state cleanup in React components
Use Context API for theme/authentication state management
Implement proper state persistence in React applications
Use React.memo for expensive components
Implement proper useCallback for handlers in React components
Use proper useMemo for expensive computations in React components
Implement proper virtualization for lists in React components
Use proper code splitting with React.lazy in React applications
Implement proper cleanup in useEffect hooks
Use proper refs for DOM access in React components
Implement proper event listener cleanup in React components
Use proper abort controllers for fetch in React components
Implement proper subscription cleanup in React components
Use proper HTML elements for semantic HTML in React components
Implement proper ARIA attributes for accessibility in React components
Use proper heading hierarchy in React components
Implement proper form labels in React components
Use proper button types in React components
Implement proper focus management for keyboard navigation in React components
Use proper keyboard shortcuts in React components
Implement proper tab order in React components
Use proper ...
Files:
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsxpackages/clerk-js/src/ui/components/APIKeys/APIKeys.tsxpackages/clerk-js/src/ui/components/UserProfile/APIKeysPage.tsx
🧬 Code graph analysis (3)
integration/tests/machine-auth/component.test.ts (1)
integration/testUtils/index.ts (1)
createTestUtils(24-86)
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsx (2)
packages/clerk-js/src/ui/contexts/components/APIKeys.ts (1)
APIKeysContext(5-5)packages/react/src/isomorphicClerk.ts (1)
organization(719-725)
packages/clerk-js/src/ui/components/APIKeys/APIKeys.tsx (1)
packages/react/src/isomorphicClerk.ts (1)
user(711-717)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (2)
packages/testing/src/playwright/unstable/page-objects/userProfile.ts (1)
20-22: NewswitchToAPIKeysTabhelper looks consistentMatches existing tab helpers (Security/Billing), keeps page-object API cohesive. No issues spotted.
packages/clerk-js/src/ui/components/OrganizationProfile/OrganizationAPIKeysPage.tsx (1)
28-33: Explicitly settingsubjecttoorganization.idis correctThis ensures org profile API keys always use the organization as subject (and overrides any accidental
subjectonapiKeysProps), aligning with the updated resolution logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
.changeset/friendly-adults-bathe.md (1)
5-6: Consider rewording for consistency with formal changelog conventions.The description uses "Fixed" but changesets typically benefit from more formal phrasing. Consider revising to "Resolved" or "Addressed" for consistency with standard changelog conventions.
Apply this diff to improve formality:
-Fixed an issue where API keys in `<UserProfile />` are showing organization API keys. +Resolved an issue where API keys in `<UserProfile />` were displaying organization API keys.This also corrects the verb tense alignment ("are showing" → "were displaying") and maintains clarity.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
.changeset/friendly-adults-bathe.md(1 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/friendly-adults-bathe.md
[style] ~5-~5: Consider using a different verb for a more formal wording.
Context: ...ed": patch "@clerk/testing": patch --- Fixed an issue where API keys in `<UserProfil...
(FIX_RESOLVE)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/shared/src/react/hooks/useAPIKeys.swr.tsx (1)
100-103: Preserve previous semantics by only sendingsubjectwhen it is setThe wrapper correctly fixes the regression by forwarding
subjectfromsafeValues, but it now always sendssubject: safeValues.subject, which means we’ll sendsubject: ''when no subject is configured. Previously, thesubjectkey was omitted entirely in that case (matching howhookParamsis built).To avoid changing behavior for the “no subject” case while still fixing the bug, consider conditionally spreading
subjecthere the same way we do inhookParams:- const result = usePagesOrInfinite({ - fetcher: clerk.apiKeys?.getAll - ? (params: GetAPIKeysParams) => clerk.apiKeys.getAll({ ...params, subject: safeValues.subject }) - : undefined, + const result = usePagesOrInfinite({ + fetcher: clerk.apiKeys?.getAll + ? (params: GetAPIKeysParams) => + clerk.apiKeys.getAll({ + ...params, + ...(safeValues.subject ? { subject: safeValues.subject } : {}), + }) + : undefined,This keeps cache scoping on
subjectwhile only sending it to the backend when it’s actually provided.packages/shared/src/react/hooks/useAPIKeys.rq.tsx (1)
98-100: Align subject forwarding with SWR hook and avoid sending emptysubjectThis change mirrors the SWR hook and fixes the missing-subject issue, but it also always sends
subject: safeValues.subject, which differs from the previous behavior (nosubjectkey when falsy).For consistency with
hookParamsand the SWR implementation, and to avoid sendingsubject: '', consider:- return usePagesOrInfinite({ - fetcher: clerk.apiKeys?.getAll - ? (params: GetAPIKeysParams) => clerk.apiKeys.getAll({ ...params, subject: safeValues.subject }) - : undefined, + return usePagesOrInfinite({ + fetcher: clerk.apiKeys?.getAll + ? (params: GetAPIKeysParams) => + clerk.apiKeys.getAll({ + ...params, + ...(safeValues.subject ? { subject: safeValues.subject } : {}), + }) + : undefined,That keeps the regression fix while preserving the old “no subject” behavior and keeps SWR/RQ hooks in sync.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/shared/src/react/hooks/useAPIKeys.rq.tsx(1 hunks)packages/shared/src/react/hooks/useAPIKeys.swr.tsx(1 hunks)
🧰 Additional context used
📓 Path-based instructions (10)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
All code must pass ESLint checks with the project's configuration
Files:
packages/shared/src/react/hooks/useAPIKeys.swr.tsxpackages/shared/src/react/hooks/useAPIKeys.rq.tsx
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/shared/src/react/hooks/useAPIKeys.swr.tsxpackages/shared/src/react/hooks/useAPIKeys.rq.tsx
packages/**/src/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/shared/src/react/hooks/useAPIKeys.swr.tsxpackages/shared/src/react/hooks/useAPIKeys.rq.tsx
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Follow established naming conventions (PascalCase for components, camelCase for variables)
Prefer importing types from
@clerk/shared/typesinstead of the deprecated@clerk/typesalias
Files:
packages/shared/src/react/hooks/useAPIKeys.swr.tsxpackages/shared/src/react/hooks/useAPIKeys.rq.tsx
packages/**/src/**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
packages/**/src/**/*.{ts,tsx,js,jsx}: Maintain comprehensive JSDoc comments for public APIs
Use tree-shaking friendly exports
Validate all inputs and sanitize outputs
All public APIs must be documented with JSDoc
Use dynamic imports for optional features
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Implement proper logging with different levels
Files:
packages/shared/src/react/hooks/useAPIKeys.swr.tsxpackages/shared/src/react/hooks/useAPIKeys.rq.tsx
**/*.ts?(x)
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
Files:
packages/shared/src/react/hooks/useAPIKeys.swr.tsxpackages/shared/src/react/hooks/useAPIKeys.rq.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.tsx: Use error boundaries in React components
Minimize re-renders in React components
**/*.tsx: Use proper type definitions for props and state in React components
Leverage TypeScript's type inference where possible in React components
Use proper event types for handlers in React components
Implement proper generic types for reusable React components
Use proper type guards for conditional rendering in React components
Files:
packages/shared/src/react/hooks/useAPIKeys.swr.tsxpackages/shared/src/react/hooks/useAPIKeys.rq.tsx
**/*.{md,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Update documentation for API changes
Files:
packages/shared/src/react/hooks/useAPIKeys.swr.tsxpackages/shared/src/react/hooks/useAPIKeys.rq.tsx
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/react.mdc)
**/*.{jsx,tsx}: Always use functional components with hooks instead of class components
Follow PascalCase naming for components (e.g.,UserProfile,NavigationMenu)
Keep components focused on a single responsibility - split large components
Limit component size to 150-200 lines; extract logic into custom hooks
Use composition over inheritance - prefer smaller, composable components
Export components as named exports for better tree-shaking
One component per file with matching filename and component name
Separate UI components from business logic components
Use useState for simple state management in React components
Use useReducer for complex state logic in React components
Implement proper state initialization in React components
Use proper state updates with callbacks in React components
Implement proper state cleanup in React components
Use Context API for theme/authentication state management
Implement proper state persistence in React applications
Use React.memo for expensive components
Implement proper useCallback for handlers in React components
Use proper useMemo for expensive computations in React components
Implement proper virtualization for lists in React components
Use proper code splitting with React.lazy in React applications
Implement proper cleanup in useEffect hooks
Use proper refs for DOM access in React components
Implement proper event listener cleanup in React components
Use proper abort controllers for fetch in React components
Implement proper subscription cleanup in React components
Use proper HTML elements for semantic HTML in React components
Implement proper ARIA attributes for accessibility in React components
Use proper heading hierarchy in React components
Implement proper form labels in React components
Use proper button types in React components
Implement proper focus management for keyboard navigation in React components
Use proper keyboard shortcuts in React components
Implement proper tab order in React components
Use proper ...
Files:
packages/shared/src/react/hooks/useAPIKeys.swr.tsxpackages/shared/src/react/hooks/useAPIKeys.rq.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Implement type guards forunknowntypes using the patternfunction isType(value: unknown): value is Type
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details in classes
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like<T extends { id: string }>
Use utility types likeOmit,Partial, andPickfor data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Useconst assertionswithas constfor literal types
Usesatisfiesoperator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...
Files:
packages/shared/src/react/hooks/useAPIKeys.swr.tsxpackages/shared/src/react/hooks/useAPIKeys.rq.tsx
🧬 Code graph analysis (2)
packages/shared/src/react/hooks/useAPIKeys.swr.tsx (1)
packages/shared/src/types/clerk.ts (1)
GetAPIKeysParams(2006-2009)
packages/shared/src/react/hooks/useAPIKeys.rq.tsx (1)
packages/shared/src/types/clerk.ts (1)
GetAPIKeysParams(2006-2009)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Build Packages
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
integration/tests/machine-auth/component.test.ts (1)
304-322: Add null check forcapturedSubjectbefore assertions.The
capturedSubjectvariable is initialized asstring | nullbut the assertions don't verify it's non-null before comparing. If the API request doesn't occur or the subject parameter is missing, the test will fail with a confusing error message (expect(null).toBe(userId)) rather than clearly indicating the request never happened.Apply this diff to add a null check:
await apiKeyRequestPromise; + // Ensure the request was captured + expect(capturedSubject).not.toBeNull(); + // Verify the subject parameter is the user ID, not the organization ID expect(capturedSubject).toBe(userId); expect(capturedSubject).not.toBe(fakeOrganization.organization.id);
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
integration/tests/machine-auth/component.test.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
All code must pass ESLint checks with the project's configuration
Files:
integration/tests/machine-auth/component.test.ts
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
integration/tests/machine-auth/component.test.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Follow established naming conventions (PascalCase for components, camelCase for variables)
Prefer importing types from
@clerk/shared/typesinstead of the deprecated@clerk/typesalias
Files:
integration/tests/machine-auth/component.test.ts
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{test,spec}.{ts,tsx,js,jsx}: Unit tests are required for all new functionality
Verify proper error handling and edge cases
Include tests for all new features
Files:
integration/tests/machine-auth/component.test.ts
**/*.ts?(x)
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
Files:
integration/tests/machine-auth/component.test.ts
**/*.{test,spec,e2e}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use real Clerk instances for integration tests
Files:
integration/tests/machine-auth/component.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/*.{ts,tsx}: Always define explicit return types for functions, especially public APIs
Use proper type annotations for variables and parameters where inference isn't clear
Avoidanytype - preferunknownwhen type is uncertain, then narrow with type guards
Implement type guards forunknowntypes using the patternfunction isType(value: unknown): value is Type
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details in classes
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Use mixins for shared behavior across unrelated classes in TypeScript
Use generic constraints with bounded type parameters like<T extends { id: string }>
Use utility types likeOmit,Partial, andPickfor data transformation instead of manual type construction
Use discriminated unions instead of boolean flags for state management and API responses
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation at the type level
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Document functions with JSDoc comments including @param, @returns, @throws, and @example tags
Create custom error classes that extend Error for specific error types
Use the Result pattern for error handling instead of throwing exceptions
Use optional chaining (?.) and nullish coalescing (??) operators for safe property access
Let TypeScript infer obvious types to reduce verbosity
Useconst assertionswithas constfor literal types
Usesatisfiesoperator for type checking without widening types
Declare readonly arrays and objects for immutable data structures
Use spread operator and array spread for immutable updates instead of mutations
Use lazy loading for large types...
Files:
integration/tests/machine-auth/component.test.ts
🧬 Code graph analysis (1)
integration/tests/machine-auth/component.test.ts (1)
integration/testUtils/index.ts (1)
createTestUtils(24-86)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Build Packages
- GitHub Check: Formatting | Dedupe | Changeset
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: semgrep-cloud-platform/scan
- GitHub Check: semgrep-cloud-platform/scan
Description
Fixes an issue where the
subjectparameter was not being passed to theclerk.apiKeys.getAll()fetcher in theuseAPIKeyshook. This causes<UserProfile />API keys page to load organization api keys when an org is active.The bug was introduced in #7270 when hooks were migrated in
@clerk/shared. Thesubjectwas placed in thetrackedobject ofcreateCacheKeys, which causedgetDifferentKeysto strip it from the request parameters before reaching the fetcher.This PR keeps the
subjectintrackedfor proper cache scoping, and explicitly pass it in the fetcher. This ensures:subjectparameter reaches the APIAdded integration test to verify UserProfile uses user ID as subject even when an organization is active
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit
Tests
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.