fix: respect next param on authenticated /login redirect
Some checks failed
CI - Production Readiness / Verify (push) Has been cancelled
Some checks failed
CI - Production Readiness / Verify (push) Has been cancelled
This commit is contained in:
@ -52,7 +52,11 @@ export async function middleware(request: NextRequest) {
|
||||
}
|
||||
|
||||
if (session && (pathname === "/" || pathname === "/login")) {
|
||||
return NextResponse.redirect(new URL(getDefaultPathForRole(session.role), baseUrl));
|
||||
const requested = request.nextUrl.searchParams.get("next");
|
||||
const hasSafeNext = typeof requested === "string" && requested.startsWith("/") && !requested.startsWith("//");
|
||||
const nextPath = hasSafeNext ? requested : null;
|
||||
const destination = nextPath && canAccessPath(session.role, nextPath) ? nextPath : getDefaultPathForRole(session.role);
|
||||
return NextResponse.redirect(new URL(destination, baseUrl));
|
||||
}
|
||||
|
||||
if (session && !isPublicPath(pathname) && !canAccessPath(session.role, pathname)) {
|
||||
|
||||
Reference in New Issue
Block a user