-
Notifications
You must be signed in to change notification settings - Fork 419
fix(backend): handle multiple token types in acceptsToken array #7527
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?
Conversation
Fixes token-type-mismatch error when using arrays in acceptsToken option. Previously, when acceptsToken was an array like ['session_token', 'api_key'], the code would always route to the machine token handler, causing session tokens to fail with token-type-mismatch errors. Now, when acceptsToken is an array, the function checks the actual token type and routes to the appropriate handler (session or machine). - Added routing logic for array acceptsToken values - Added tests for mixed token type arrays - Preserves backward compatibility with existing usage Fixes clerk#7520
🦋 Changeset detectedLatest commit: a90fad5 The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 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 |
|
@Ayush2k02 is attempting to deploy a commit to the Clerk Production Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThis pull request fixes authentication request routing when Pre-merge checks✅ Passed checks (5 passed)
📜 Recent review detailsConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (3)
🧰 Additional context used📓 Path-based instructions (13)**/*.{js,jsx,ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{js,jsx,ts,tsx,json,md,yml,yaml}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
packages/**/src/**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
packages/**/src/**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.ts?(x)📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/typescript.mdc)
Files:
**/*.{js,ts,jsx,tsx}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
**/*.{js,ts,jsx,tsx,json,md,yml,yaml}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
**/*⚙️ CodeRabbit configuration file
Files:
**/*.{test,spec}.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.{test,spec,e2e}.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (.cursor/rules/development.mdc)
Files:
**/*.test.{ts,tsx}📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)
Files:
🧬 Code graph analysis (2)packages/backend/src/tokens/request.ts (1)
packages/backend/src/tokens/__tests__/request.test.ts (3)
⏰ 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). (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes token-type-mismatch error when using multiple
acceptsTokenvalues inauthenticateRequest.Problem
When
acceptsTokenis an array containing both session and machine token types (e.g.,['session_token', 'api_key']), the function would always route to the machine token authentication handler, causing session tokens to fail withtoken-type-mismatcherrors.Root Cause
In request.ts:784-792, the routing logic checked:
When
acceptsTokenis['session_token', 'api_key'], the conditionacceptsToken === TokenType.SessionTokenevaluates tofalse(array !== string), causing all tokens to be routed toauthenticateMachineRequestWithTokenInHeader().Solution
Added routing logic that checks the actual token type when
acceptsTokenis an array:Now:
Changes
authenticateRequestinpackages/backend/src/tokens/request.tsto handle array routing correctlysession_tokenin array with machine tokensapi_keyin array withsession_tokenTesting
Added two new test cases:
session_tokenis accepted when in array withapi_keyapi_keyis accepted when in array withsession_tokenBoth scenarios now work correctly without token-type-mismatch errors.
Backward Compatibility
This change is fully backward compatible:
Fixes #7520
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.