Send Better Auth session token with tRPC

This commit is contained in:
2026-06-29 18:38:47 -04:00
parent 57e1aa658a
commit 0aa1b0b431
+11 -3
View File
@@ -7,6 +7,8 @@ import { normalizeSecureStoreKey } from "@/lib/secure-store-keys";
type AuthClient = ReturnType<typeof createAuthClient>; type AuthClient = ReturnType<typeof createAuthClient>;
const CHUNK_MARKER = "\u0001ba-chunks:"; const CHUNK_MARKER = "\u0001ba-chunks:";
const SESSION_TOKEN_COOKIE_PART =
/(?:^|;\s*)(?:__Secure-)?[^=]*session_token=([^;]+)/;
function readSecureStoreValueSync(key: string): string | null { function readSecureStoreValueSync(key: string): string | null {
const value = SecureStore.getItem(key); const value = SecureStore.getItem(key);
@@ -49,7 +51,13 @@ export function getAuthCookieHeaders(
storagePrefix: string, storagePrefix: string,
): Record<string, string> { ): Record<string, string> {
const cookie = getAuthCookie(authClient, storagePrefix); const cookie = getAuthCookie(authClient, storagePrefix);
return cookie if (!cookie) return {};
? { cookie, Cookie: cookie, "x-beenvoice-auth-cookie": cookie }
: {}; const sessionToken = cookie.match(SESSION_TOKEN_COOKIE_PART)?.[1];
return {
cookie,
Cookie: cookie,
"x-beenvoice-auth-cookie": cookie,
...(sessionToken ? { "x-beenvoice-session-token": sessionToken } : {}),
};
} }