Files
Jyotisha/frontend/src/proxy.ts
T
ClaudeandClaude Opus 5.5 837155f5ba
Independent Staging Quality Gate / validate-frontend (push) Successful in 6m17s
Independent Staging Quality Gate / validate-python (push) Successful in 6m33s
Independent Staging Quality Gate / publish (push) Successful in 3m12s
fix: redirect signed-out / on the server; login tabs and code boxes; rectification starts at once (BUG-1535)
- proxy.ts: no session cookie on `/` → 307 /login before any page code, so the
  shell and 正在载入账户 no longer flash first
- login: segmented tabs fill the width and fit their track; six code boxes
  span the form like the email field
- /rectification: drop the 先核对一下资料 step; every button sits in one row
  at the card's foot instead of one inside and one below

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-03 22:58:42 +08:00

36 lines
1.3 KiB
TypeScript

import { NextResponse, type NextRequest } from "next/server";
import { homeNeedsLoginRedirect } from "@/lib/home-login-gate";
import { readIdentityConfig } from "@/modules/identity/config";
import { resolveIdentitySurface } from "@/modules/identity/host";
export function proxy(request: NextRequest) {
let config;
try {
config = readIdentityConfig(process.env);
} catch {
// A misconfigured server keeps the page's own error screen.
return NextResponse.next();
}
const adminSurface = config.provider === "self-hosted"
&& resolveIdentitySurface(request.headers.get("host"), config) === "admin";
const redirect = homeNeedsLoginRedirect({
provider: config.provider,
cookieNames: request.cookies.getAll().map((cookie) => cookie.name),
previewRequested: process.env.NODE_ENV === "development" && request.nextUrl.searchParams.has("preview"),
adminSurface,
});
if (!redirect) return NextResponse.next();
// Self-hosted: the configured public origin, never the container address behind Caddy.
const login = config.provider === "self-hosted"
? new URL("/login", config.userOrigin)
: new URL("/login", request.nextUrl.origin);
const response = NextResponse.redirect(login, 307);
response.headers.set("Cache-Control", "no-store");
return response;
}
export const config = {
matcher: "/",
};