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}/`));
|
const isLogin = PUBLIC.some((p) => pathname === p || pathname.startsWith(`${p}/`));
|
||||||
|
|
||||||
if (!session && !isLogin) {
|
if (!session && !isLogin) {
|
||||||
const url = request.nextUrl.clone();
|
// Relative redirect: behind Caddy, request.nextUrl host is localhost:4015.
|
||||||
url.pathname = "/login";
|
const next = encodeURIComponent(pathname);
|
||||||
url.searchParams.set("next", pathname);
|
return NextResponse.redirect(`/login?next=${next}`);
|
||||||
return NextResponse.redirect(url);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session && isLogin) {
|
if (session && isLogin) {
|
||||||
return NextResponse.redirect(new URL("/", request.url));
|
return NextResponse.redirect("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.next();
|
return NextResponse.next();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user