feat(login): enhance routing by preserving 'from' path in login redirects

This commit is contained in:
2026-03-12 01:14:16 +08:00
parent 2479653bab
commit 4e16e933f2
2 changed files with 5 additions and 3 deletions

View File

@@ -63,7 +63,8 @@ export async function middleware(request: NextRequest) {
if (!sessionCookie) {
const loginUrl = new URL("/login", request.url);
loginUrl.searchParams.set("from", pathname);
const fromPath = request.nextUrl.search ? pathname + request.nextUrl.search : pathname;
loginUrl.searchParams.set("from", fromPath);
const res = NextResponse.redirect(loginUrl);
if (!fromCache) res.cookies.set("helios_setup_done", "1", { path: "/", httpOnly: true, sameSite: "lax" });
return res;