fix: it.sam/ exige sesion antes del rewrite
This commit is contained in:
1 parent
c6a629cf7b
commit
91b0220e46
1 file changed
+12
-7
+12
-7
@@ -14,23 +14,28 @@ function isProtected(path: string): boolean {
|
||||
|
||||
export async function middleware(req: NextRequest) {
|
||||
const host = (req.headers.get("host") || "").toLowerCase();
|
||||
if (host.startsWith("it.sam.") && req.nextUrl.pathname === "/") {
|
||||
const url = req.nextUrl.clone();
|
||||
url.pathname = "/tablero";
|
||||
return NextResponse.rewrite(url);
|
||||
}
|
||||
if (req.nextUrl.pathname === "/m/portal" || req.nextUrl.pathname.startsWith("/m/portal/")) {
|
||||
return NextResponse.redirect(IT_BOARD);
|
||||
}
|
||||
if (isProtected(req.nextUrl.pathname)) {
|
||||
// it.sam/ equivale a /tablero (protegido): se evalúa con ese path
|
||||
const effective =
|
||||
host.startsWith("it.sam.") && req.nextUrl.pathname === "/"
|
||||
? "/tablero"
|
||||
: req.nextUrl.pathname;
|
||||
if (isProtected(effective)) {
|
||||
const sess = await readSession(req.cookies.get(COOKIE)?.value);
|
||||
if (!sess) {
|
||||
const url = req.nextUrl.clone();
|
||||
url.pathname = "/login";
|
||||
url.searchParams.set("next", req.nextUrl.pathname);
|
||||
url.searchParams.set("next", effective);
|
||||
return NextResponse.redirect(url);
|
||||
}
|
||||
}
|
||||
if (effective !== req.nextUrl.pathname) {
|
||||
const url = req.nextUrl.clone();
|
||||
url.pathname = effective;
|
||||
return NextResponse.rewrite(url);
|
||||
}
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user