import { NextRequest, NextResponse } from "next/server"; const protectedRoutes = ["/dashboard", "/tasks", "/schedule", "/announcements", "/store", "/me"]; const publicRoutes = ["/", "/login"]; const cookieName = process.env.ROLE_USER_SESSION_COOKIE || "role_user_session"; export function proxy(request: NextRequest) { const path = request.nextUrl.pathname; const hasSession = Boolean(request.cookies.get(cookieName)?.value); const isProtected = protectedRoutes.some((route) => path === route || path.startsWith(`${route}/`)); const isPublic = publicRoutes.includes(path); if (isProtected && !hasSession) { return NextResponse.redirect(new URL("/login", request.url)); } if (isPublic && hasSession) { return NextResponse.redirect(new URL("/dashboard", request.url)); } return NextResponse.next(); } export const config = { matcher: ["/((?!api|_next/static|_next/image|manifest.webmanifest|sw.js|.*\\..*).*)"] };