Fix login redirect missing basePath behind reverse proxy

Use request.nextUrl.clone() instead of new URL("/login", request.url)
so Next.js includes the /hp-prod-tracker basePath in redirects.
Without this, unauthenticated users get sent to /login instead of
/hp-prod-tracker/login.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
DJP 2026-04-13 15:26:51 -04:00
parent 58d8459b43
commit 30f804b7ff

View file

@ -52,7 +52,9 @@ export function middleware(request: NextRequest) {
// Redirect logged-in users away from login page
if (isAuthPage && isLoggedIn) {
return NextResponse.redirect(new URL("/dashboard", request.url));
const url = request.nextUrl.clone();
url.pathname = "/dashboard";
return NextResponse.redirect(url);
}
// Allow authenticated users to access the pending page
@ -65,7 +67,9 @@ export function middleware(request: NextRequest) {
if (pathname.startsWith("/api/")) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
return NextResponse.redirect(new URL("/login", request.url));
const url = request.nextUrl.clone();
url.pathname = "/login";
return NextResponse.redirect(url);
}
return NextResponse.next();