feat(auth): enhance AuthContext for server-side handling#2729
Open
pedrofrxncx wants to merge 1 commit intomainfrom
Open
feat(auth): enhance AuthContext for server-side handling#2729pedrofrxncx wants to merge 1 commit intomainfrom
pedrofrxncx wants to merge 1 commit intomainfrom
Conversation
Added a new `serverSide` property to the `AuthContext` interface to manage MCP OAuth and API key sessions more effectively. Updated the `createBoundAuthClient` function to conditionally use empty headers for server-side calls, ensuring compatibility with Better Auth's session middleware. Adjusted related functions to utilize the new property for user ID resolution and header management.
Contributor
🧪 BenchmarkShould we run the Virtual MCP strategy benchmark for this PR? React with 👍 to run the benchmark.
Benchmark will run on the next push after you react. |
Contributor
Release OptionsShould a new version be published when this PR is merged? React with an emoji to vote on the release type:
Current version: Deployment
|
Contributor
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/mesh/src/core/context-factory.ts">
<violation number="1" location="apps/mesh/src/core/context-factory.ts:312">
P2: Clearing headers here breaks `organization.get()` for server-side auth because existing callers rely on the active organization from session and do not pass an `organizationId`.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| get: async (organizationId) => { | ||
| return auth.api.getFullOrganization({ | ||
| headers, | ||
| headers: serverSide ? serverHeaders : headers, |
Contributor
There was a problem hiding this comment.
P2: Clearing headers here breaks organization.get() for server-side auth because existing callers rely on the active organization from session and do not pass an organizationId.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/mesh/src/core/context-factory.ts, line 312:
<comment>Clearing headers here breaks `organization.get()` for server-side auth because existing callers rely on the active organization from session and do not pass an `organizationId`.</comment>
<file context>
@@ -303,15 +309,16 @@ export function createBoundAuthClient(ctx: AuthContext): BoundAuthClient {
get: async (organizationId) => {
return auth.api.getFullOrganization({
- headers,
+ headers: serverSide ? serverHeaders : headers,
query: organizationId ? { organizationId } : undefined,
});
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added a new
serverSideproperty to theAuthContextinterface to manage MCP OAuth and API key sessions more effectively. Updated thecreateBoundAuthClientfunction to conditionally use empty headers for server-side calls, ensuring compatibility with Better Auth's session middleware. Adjusted related functions to utilize the new property for user ID resolution and header management.What is this contribution about?
Screenshots/Demonstration
How to Test
Migration Notes
Review Checklist
Summary by cubic
Adds a
serverSideflag toAuthContextand routes server-side MCP OAuth/API key flows withoutAuthorizationheaders to keep Better Auth session middleware from mis-resolving tokens. This fixes org/member queries on the server by using query/body params and correct user scoping.createBoundAuthClient: whenserverSide, sends empty headers to Better Auth and relies on query/body params instead of Bearer tokens.userIdor falls back to contextuserId.authenticateRequestand setsserverSideincreateMeshContextFactorywhen MCP OAuth or API key is detected.Written for commit 6fdb139. Summary will update on new commits.