Polish mobile and web experience
This commit is contained in:
@@ -11,6 +11,18 @@ const CHUNK_MARKER = "\u0001ba-chunks:";
|
||||
const SESSION_TOKEN_COOKIE_PART =
|
||||
/(?:^|;\s*)(?:__Secure-)?[^=]*session_token=([^;]+)/;
|
||||
const AUTH_COOKIE_DEBUG = process.env.EXPO_PUBLIC_AUTH_COOKIE_DEBUG === "1";
|
||||
const lastAuthCookieDebugState = new Map<string, string>();
|
||||
|
||||
function debugAuthCookie(event: string, storagePrefix: string, details: Record<string, unknown>) {
|
||||
if (!AUTH_COOKIE_DEBUG) return;
|
||||
|
||||
const key = `${event}:${storagePrefix}`;
|
||||
const state = JSON.stringify(details);
|
||||
if (lastAuthCookieDebugState.get(key) === state) return;
|
||||
|
||||
lastAuthCookieDebugState.set(key, state);
|
||||
console.info(`[auth-cookie] ${event}`, { storagePrefix, ...details });
|
||||
}
|
||||
|
||||
function readSecureStoreValueSync(key: string): string | null {
|
||||
const value = SecureStore.getItem(key);
|
||||
@@ -56,25 +68,19 @@ export function getAuthCookie(
|
||||
).getCookie?.();
|
||||
if (fromClient?.trim()) {
|
||||
const cookie = fromClient.trim();
|
||||
if (AUTH_COOKIE_DEBUG) {
|
||||
console.info("[auth-cookie] using client cookie", {
|
||||
storagePrefix,
|
||||
length: cookie.length,
|
||||
names: cookieNames(cookie),
|
||||
});
|
||||
}
|
||||
debugAuthCookie("using client cookie", storagePrefix, {
|
||||
length: cookie.length,
|
||||
names: cookieNames(cookie),
|
||||
});
|
||||
return cookie;
|
||||
}
|
||||
|
||||
const fromPrefix = readStoredCookie(storagePrefix);
|
||||
if (fromPrefix) {
|
||||
if (AUTH_COOKIE_DEBUG) {
|
||||
console.info("[auth-cookie] using stored cookie", {
|
||||
storagePrefix,
|
||||
length: fromPrefix.length,
|
||||
names: cookieNames(fromPrefix),
|
||||
});
|
||||
}
|
||||
debugAuthCookie("using stored cookie", storagePrefix, {
|
||||
length: fromPrefix.length,
|
||||
names: cookieNames(fromPrefix),
|
||||
});
|
||||
return fromPrefix;
|
||||
}
|
||||
|
||||
@@ -82,18 +88,15 @@ export function getAuthCookie(
|
||||
storagePrefix === GUEST_AUTH_STORAGE_PREFIX
|
||||
? null
|
||||
: readStoredCookie(GUEST_AUTH_STORAGE_PREFIX);
|
||||
if (AUTH_COOKIE_DEBUG) {
|
||||
console.info("[auth-cookie] resolved tRPC cookie", {
|
||||
storagePrefix,
|
||||
fallbackPrefix:
|
||||
fromGuest && storagePrefix !== GUEST_AUTH_STORAGE_PREFIX
|
||||
? GUEST_AUTH_STORAGE_PREFIX
|
||||
: null,
|
||||
hasCookie: Boolean(fromGuest),
|
||||
length: fromGuest?.length ?? 0,
|
||||
names: fromGuest ? cookieNames(fromGuest) : [],
|
||||
});
|
||||
}
|
||||
debugAuthCookie("resolved tRPC cookie", storagePrefix, {
|
||||
fallbackPrefix:
|
||||
fromGuest && storagePrefix !== GUEST_AUTH_STORAGE_PREFIX
|
||||
? GUEST_AUTH_STORAGE_PREFIX
|
||||
: null,
|
||||
hasCookie: Boolean(fromGuest),
|
||||
length: fromGuest?.length ?? 0,
|
||||
names: fromGuest ? cookieNames(fromGuest) : [],
|
||||
});
|
||||
return fromGuest;
|
||||
}
|
||||
|
||||
@@ -103,21 +106,16 @@ export function getAuthCookieHeaders(
|
||||
): Record<string, string> {
|
||||
const cookie = getAuthCookie(authClient, storagePrefix);
|
||||
if (!cookie) {
|
||||
if (AUTH_COOKIE_DEBUG) {
|
||||
console.info("[auth-cookie] no tRPC auth cookie", { storagePrefix });
|
||||
}
|
||||
debugAuthCookie("no tRPC auth cookie", storagePrefix, {});
|
||||
return {};
|
||||
}
|
||||
|
||||
const sessionToken = cookie.match(SESSION_TOKEN_COOKIE_PART)?.[1];
|
||||
if (AUTH_COOKIE_DEBUG) {
|
||||
console.info("[auth-cookie] sending tRPC auth headers", {
|
||||
storagePrefix,
|
||||
cookieLength: cookie.length,
|
||||
cookieNames: cookieNames(cookie),
|
||||
hasSessionTokenHeader: Boolean(sessionToken),
|
||||
});
|
||||
}
|
||||
debugAuthCookie("sending tRPC auth headers", storagePrefix, {
|
||||
cookieLength: cookie.length,
|
||||
cookieNames: cookieNames(cookie),
|
||||
hasSessionTokenHeader: Boolean(sessionToken),
|
||||
});
|
||||
return {
|
||||
cookie,
|
||||
Cookie: cookie,
|
||||
|
||||
Reference in New Issue
Block a user