Skip to content

Commit 0a099b7

Browse files
jsell-rhclaude
andcommitted
fix(ambient-ui): split custom token into separate cookie to avoid overflow
The custom connection token was stored in the main iron-session cookie, which also holds SSO access/refresh tokens. This caused cookie-too-large errors. Move the custom token to a second iron-session cookie (ambient-ui-session-ctx) so auth and context don't compete for space. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cea4a27 commit 0a099b7

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

components/ambient-ui/src/lib/runtime-config.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { env } from './env'
2-
import { getSession } from './session'
2+
import { getSession, getContextSession } from './session'
33

44
export type RuntimeConfig = {
55
apiServerUrl: string
@@ -12,8 +12,9 @@ export async function getRuntimeConfig(): Promise<RuntimeConfig> {
1212
const defaultUrl = env.API_SERVER_URL
1313
try {
1414
const session = await getSession()
15+
const ctxSession = await getContextSession()
1516
const apiServerUrl = session.customApiServerUrl || defaultUrl
16-
const customToken = session.customToken ?? null
17+
const customToken = ctxSession.customToken ?? null
1718
return {
1819
apiServerUrl,
1920
customToken,
@@ -32,18 +33,22 @@ export async function getRuntimeConfig(): Promise<RuntimeConfig> {
3233

3334
export async function setCustomContext(url?: string, token?: string | null): Promise<void> {
3435
const session = await getSession()
36+
const ctxSession = await getContextSession()
3537
if (url) session.customApiServerUrl = url
3638
if (token === null || token === '') {
37-
session.customToken = undefined
39+
ctxSession.customToken = undefined
3840
} else if (token) {
39-
session.customToken = token
41+
ctxSession.customToken = token
4042
}
4143
await session.save()
44+
await ctxSession.save()
4245
}
4346

4447
export async function resetContext(): Promise<void> {
4548
const session = await getSession()
49+
const ctxSession = await getContextSession()
4650
session.customApiServerUrl = undefined
47-
session.customToken = undefined
51+
ctxSession.customToken = undefined
4852
await session.save()
53+
await ctxSession.save()
4954
}

components/ambient-ui/src/lib/session.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export type SessionData = {
99
expiresAt: number
1010
customApiServerUrl?: string
1111
customTokenId?: string
12+
}
13+
14+
export type ContextSessionData = {
1215
customToken?: string
1316
}
1417

@@ -48,6 +51,14 @@ export async function getSession() {
4851
return getIronSession<SessionData>(await cookies(), getSessionOptions())
4952
}
5053

54+
export async function getContextSession() {
55+
const opts = getSessionOptions()
56+
return getIronSession<ContextSessionData>(await cookies(), {
57+
...opts,
58+
cookieName: `${opts.cookieName}-ctx`,
59+
})
60+
}
61+
5162
export async function getAccessToken(): Promise<string | undefined> {
5263
const session = await getSession()
5364
if (!session.accessToken) return undefined

0 commit comments

Comments
 (0)