Send Better Auth session token with tRPC
This commit is contained in:
+11
-3
@@ -7,6 +7,8 @@ import { normalizeSecureStoreKey } from "@/lib/secure-store-keys";
|
||||
type AuthClient = ReturnType<typeof createAuthClient>;
|
||||
|
||||
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<string, string> {
|
||||
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 } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user