Harden auth profile fallback for slow backend responses

This commit is contained in:
2569718930@qq.com
2026-04-15 22:40:01 +08:00
parent c4b45be757
commit 62298eaf38
2 changed files with 55 additions and 7 deletions
+7 -3
View File
@@ -9,6 +9,8 @@ export const FORWARDED_SUPABASE_EMAIL_HEADER = "x-polyweather-auth-email";
type HeaderBuildResult = {
headers: HeadersInit;
response: NextResponse | null;
authUserId?: string | null;
authEmail?: string | null;
};
type HeaderBuildOptions = {
@@ -59,20 +61,20 @@ export async function buildBackendRequestHeaders(
if (incomingAuth) {
headers.set("Authorization", `Bearer ${incomingAuth}`);
return { headers, response: passthroughResponse };
return { headers, response: passthroughResponse, authUserId: forwardedUserId || null, authEmail: forwardedEmail || null };
}
const accessToken = session?.access_token || "";
if (accessToken) {
// Fallback to cookie-backed session when request does not carry bearer.
headers.set("Authorization", `Bearer ${accessToken}`);
}
return { headers, response: passthroughResponse };
return { headers, response: passthroughResponse, authUserId: forwardedUserId || null, authEmail: forwardedEmail || null };
}
if (incomingAuth) {
headers.set("Authorization", `Bearer ${incomingAuth}`);
}
return { headers, response: null };
return { headers, response: null, authUserId: null, authEmail: null };
}
export function applyAuthResponseCookies(
@@ -87,3 +89,5 @@ export function applyAuthResponseCookies(
}
return target;
}