fix: use relative login redirects behind reverse proxy
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
01a0ab351f
commit
117c981275
@ -26,14 +26,13 @@ export function middleware(request: NextRequest) {
|
||||
const isLogin = PUBLIC.some((p) => pathname === p || pathname.startsWith(`${p}/`));
|
||||
|
||||
if (!session && !isLogin) {
|
||||
const url = request.nextUrl.clone();
|
||||
url.pathname = "/login";
|
||||
url.searchParams.set("next", pathname);
|
||||
return NextResponse.redirect(url);
|
||||
// Relative redirect: behind Caddy, request.nextUrl host is localhost:4015.
|
||||
const next = encodeURIComponent(pathname);
|
||||
return NextResponse.redirect(`/login?next=${next}`);
|
||||
}
|
||||
|
||||
if (session && isLogin) {
|
||||
return NextResponse.redirect(new URL("/", request.url));
|
||||
return NextResponse.redirect("/");
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user