Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/purple-peas-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clerk/react-router": patch
---

Fixed an issue where manually specified options in the middleware were not being respected.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ describe('clerkMiddleware', () => {
const result = await middleware(args, mockNext);

expect(mockAuthenticateRequest).toHaveBeenCalledWith(expect.any(Object), {
apiUrl: undefined,
secretKey: 'sk_test_...',
jwtKey: undefined,
proxyUrl: undefined,
isSatellite: undefined,
domain: undefined,
publishableKey: 'pk_test_...',
machineSecretKey: undefined,
audience: '',
authorizedParties: [],
signInUrl: '',
Expand Down
34 changes: 30 additions & 4 deletions packages/react-router/src/server/clerkMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,39 @@ export const clerkMiddleware = (options?: ClerkMiddlewareOptions): MiddlewareFun
return async (args, next) => {
const clerkRequest = createClerkRequest(patchRequest(args.request));
const loadedOptions = loadOptions(args, options);
const { audience, authorizedParties } = loadedOptions;
const { signInUrl, signUpUrl, afterSignInUrl, afterSignUpUrl } = loadedOptions;
const { organizationSyncOptions } = loadedOptions;
const requestState = await clerkClient(args).authenticateRequest(clerkRequest, {

// Pick only the properties needed by authenticateRequest.
// Used when manually providing options to the middleware.
const {
apiUrl,
secretKey,
jwtKey,
proxyUrl,
isSatellite,
domain,
publishableKey,
machineSecretKey,
audience,
authorizedParties,
signInUrl,
signUpUrl,
afterSignInUrl,
afterSignUpUrl,
organizationSyncOptions,
} = loadedOptions;

const requestState = await clerkClient(args).authenticateRequest(clerkRequest, {
apiUrl,
secretKey,
jwtKey,
proxyUrl,
isSatellite,
domain,
publishableKey,
machineSecretKey,
audience,
authorizedParties,
organizationSyncOptions,
signInUrl,
signUpUrl,
afterSignInUrl,
Expand Down
Loading