diff --git a/lib/auth-cookie.ts b/lib/auth-cookie.ts index 041060e..ffb603e 100644 --- a/lib/auth-cookie.ts +++ b/lib/auth-cookie.ts @@ -7,6 +7,8 @@ import { normalizeSecureStoreKey } from "@/lib/secure-store-keys"; type AuthClient = ReturnType; const CHUNK_MARKER = "\u0001ba-chunks:"; +const SESSION_TOKEN_COOKIE_PART = + /(?:^|;\s*)(?:__Secure-)?[^=]*session_token=([^;]+)/; function readSecureStoreValueSync(key: string): string | null { const value = SecureStore.getItem(key); @@ -49,7 +51,13 @@ export function getAuthCookieHeaders( storagePrefix: string, ): Record { const cookie = getAuthCookie(authClient, storagePrefix); - return cookie - ? { cookie, Cookie: cookie, "x-beenvoice-auth-cookie": cookie } - : {}; + if (!cookie) return {}; + + const sessionToken = cookie.match(SESSION_TOKEN_COOKIE_PART)?.[1]; + return { + cookie, + Cookie: cookie, + "x-beenvoice-auth-cookie": cookie, + ...(sessionToken ? { "x-beenvoice-session-token": sessionToken } : {}), + }; }