- 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
36 lines
1.3 KiB
TypeScript
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: "/",
|
|
};
|