From 0aa1b0b4318ded0f1c766b078e0ad7aea1470f75 Mon Sep 17 00:00:00 2001 From: Sean O'Connor Date: Mon, 29 Jun 2026 18:38:47 -0400 Subject: [PATCH] Send Better Auth session token with tRPC --- lib/auth-cookie.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 } : {}), + }; }