-
Couldn't load subscription status.
- Fork 402
fix(react-router): Respect manual configuration options in middleware #7079
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: d9f972c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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.
|
WalkthroughA patch release for @clerk/react-router fixes a bug where manually specified middleware options (keys, URLs, domain settings) were not being passed to authenticateRequest. The implementation now forwards all relevant options including publishableKey, secretKey, apiUrl, proxyUrl, and other configuration to the authentication request handler. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 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 (1)
packages/react-router/src/server/__tests__/clerkMiddleware.test.ts (1)
67-83: Test expectations updated correctly, but consider adding coverage for the bug fix.The test expectations now match the new
authenticateRequestsignature. However, there's no test case that specifically validates the bug fix - i.e., that manually provided options (especially keys) are actually passed through toauthenticateRequest.Consider adding a test case like this:
it('should pass manually specified keys to authenticateRequest', async () => { const mockRequestState = { status: AuthStatus.SignedIn, headers: new Headers(), toAuth: vi.fn().mockReturnValue({ userId: 'user_xxx', tokenType: TokenType.SessionToken }), }; const mockAuthenticateRequest = vi.fn().mockResolvedValue(mockRequestState); mockClerkClient.mockReturnValue({ authenticateRequest: mockAuthenticateRequest, } as unknown as ClerkClient); const customOptions: ClerkMiddlewareOptions = { publishableKey: 'pk_custom_...', secretKey: 'sk_custom_...', }; mockLoadOptions.mockReturnValue({ ...mockLoadOptions.mock.results[0].value, publishableKey: 'pk_custom_...', secretKey: 'sk_custom_...', } as ReturnType<typeof loadOptions>); const middleware = clerkMiddleware(customOptions); const args = { request: new Request('http://clerk.com'), context: mockContext, } as LoaderFunctionArgs; const mockResponse = new Response('OK'); mockNext.mockResolvedValue(mockResponse); await middleware(args, mockNext); // Verify custom keys are passed through expect(mockAuthenticateRequest).toHaveBeenCalledWith( expect.any(Object), expect.objectContaining({ publishableKey: 'pk_custom_...', secretKey: 'sk_custom_...', }) ); });
📜 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 (3)
.changeset/purple-peas-shave.md(1 hunks)packages/react-router/src/server/__tests__/clerkMiddleware.test.ts(1 hunks)packages/react-router/src/server/clerkMiddleware.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (9)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
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
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels
Files:
packages/react-router/src/server/__tests__/clerkMiddleware.test.tspackages/react-router/src/server/clerkMiddleware.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use Prettier for consistent code formatting
Files:
packages/react-router/src/server/__tests__/clerkMiddleware.test.tspackages/react-router/src/server/clerkMiddleware.ts
packages/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
TypeScript is required for all packages
Files:
packages/react-router/src/server/__tests__/clerkMiddleware.test.tspackages/react-router/src/server/clerkMiddleware.ts
packages/**/*.{ts,tsx,d.ts}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Packages should export TypeScript types alongside runtime code
Files:
packages/react-router/src/server/__tests__/clerkMiddleware.test.tspackages/react-router/src/server/clerkMiddleware.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Use proper TypeScript error types
**/*.{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
Useinterfacefor object shapes that might be extended
Usetypefor unions, primitives, and computed types
Preferreadonlyproperties for immutable data structures
Useprivatefor internal implementation details
Useprotectedfor inheritance hierarchies
Usepublicexplicitly for clarity in public APIs
Preferreadonlyfor properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Useconst assertionsfor literal types:as const
Usesatisfiesoperator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports:import type { ... } from ...
Noanytypes without justification
Proper error handling with typed errors
Consistent use ofreadonlyfor immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)
Files:
packages/react-router/src/server/__tests__/clerkMiddleware.test.tspackages/react-router/src/server/clerkMiddleware.ts
packages/**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Unit tests should use Jest or Vitest as the test runner.
Files:
packages/react-router/src/server/__tests__/clerkMiddleware.test.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.
Files:
packages/react-router/src/server/__tests__/clerkMiddleware.test.tspackages/react-router/src/server/clerkMiddleware.ts
**/__tests__/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
**/__tests__/**/*.{ts,tsx}: Create type-safe test builders/factories
Use branded types for test isolation
Implement proper mock types that match interfaces
Files:
packages/react-router/src/server/__tests__/clerkMiddleware.test.ts
.changeset/**
📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Automated releases must use Changesets.
Files:
.changeset/purple-peas-shave.md
🧬 Code graph analysis (1)
packages/react-router/src/server/clerkMiddleware.ts (1)
packages/react-router/src/server/clerkClient.ts (1)
clerkClient(5-21)
🪛 LanguageTool
.changeset/purple-peas-shave.md
[style] ~4-~4: Consider using a different verb for a more formal wording.
Context: --- "@clerk/react-router": patch --- Fixed an issue where manually specified optio...
(FIX_RESOLVE)
🔇 Additional comments (3)
packages/react-router/src/server/clerkMiddleware.ts (2)
58-75: Correctly forwards all options to authenticateRequest.The implementation properly passes all destructured options to
authenticateRequest, ensuring that manually specified configuration (keys, URLs, etc.) is respected. This is the core fix for issue #7073.
37-56: Verification confirms the destructuring fix is correct.All 15 destructured properties from
loadedOptionsare correctly passed toauthenticateRequest(). The type definition confirmsorganizationSyncOptionsis a validAuthenticateRequestOptionsproperty, and the implementation matches the pattern used in other framework integrations (express, remix, nuxt).The fix properly addresses the reported issue where manually specified options (keys, URLs, organization settings) were being ignored by ensuring they're extracted and passed through to the authentication handler.
.changeset/purple-peas-shave.md (1)
1-5: Changeset correctly documents the patch fix.The changeset properly specifies a patch version bump and clearly describes the bug fix. The static analysis suggestion to use a different verb is a false positive - "Fixed" is standard terminology for bug fix changesets.
Description
This PR allows manually overriding options being passed to
authenticateRequest()in React Router'sclerkMiddleware()Fixes #7073
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
Summary by CodeRabbit