Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions apps/login/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ export async function proxy(request: NextRequest) {
// Add the original URL as a header to all requests
const requestHeaders = new Headers(request.headers);

// Strip malformed Next-Router-State-Tree headers to prevent Next.js from
// throwing "The router state header was sent but could not be parsed."
// This happens when stale clients (pre-deployment) send incomplete router state.
const routerStateHeader = requestHeaders.get("Next-Router-State-Tree");
if (routerStateHeader) {
let isValid = false;
try {
const parsed = JSON.parse(decodeURIComponent(routerStateHeader));
isValid = Array.isArray(parsed) && parsed.length >= 2;
} catch {
isValid = false;
}
if (!isValid) {
requestHeaders.delete("Next-Router-State-Tree");
requestHeaders.delete("Rsc");
requestHeaders.delete("Next-Router-Prefetch");
}
}

// Extract "organization" search param from the URL and set it as a header if available
const organization = request.nextUrl.searchParams.get("organization");
if (organization) {
Expand Down
Loading