Skip to content

Commit 8781956

Browse files
venatiromeraplak
andauthored
fix(auth-context): retain context in response body and options for user authentication (#676)
* fix(auth-context): retain context in response body and options for user authentication * chore: add changeset --------- Co-authored-by: Omer Aplak <[email protected]>
1 parent ec02400 commit 8781956

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

.changeset/lovely-swans-doubt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@voltagent/server-hono": patch
3+
---
4+
5+
fix(auth-context): retain context in response body and options for user authentication

packages/server-hono/src/auth/middleware.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,27 @@ export function createAuthMiddleware(authProvider: AuthProvider<Request>) {
6767
const body = await originalJson();
6868
return {
6969
...body,
70+
// Not removing context from body as it might be used somewhere else
7071
context: {
7172
...body.context,
7273
user,
7374
},
7475
// Set userId if available
7576
...(user.id && { userId: user.id }),
7677
...(user.sub && !user.id && { userId: user.sub }),
78+
// Adding the above in options, as this is where context is read from
79+
// by processAgentOptions (packages/server-core/src/utils/options.ts:37)
80+
// and processWorkflowOptions
81+
// These is needed so the auth context/user arrives into OperationContext
82+
options: {
83+
context: {
84+
...body.context,
85+
user,
86+
},
87+
// Set userId if available
88+
...(user.id && { userId: user.id }),
89+
...(user.sub && !user.id && { userId: user.sub }),
90+
},
7791
};
7892
};
7993

0 commit comments

Comments
 (0)