//export { auth as proxy } from "@/auth"; import { auth } from "@/auth"; // export const proxy = auth((req) => { // if (!req.auth && req.nextUrl.pathname !== "/login") { // const newUrl = new URL("/login", req.nextUrl.origin); // return Response.redirect(newUrl); // } // }); export const proxy = auth((req) => { const { pathname } = req.nextUrl; const isAuthRoute = pathname === "/login" || pathname === "/register"; // If user is not authenticated and not visiting an auth page, redirect to login if (!req.auth && !isAuthRoute) { const newUrl = new URL("/login", req.nextUrl.origin); return Response.redirect(newUrl); } // (Optional) If the user IS authenticated, prevent them from visiting login/register if (req.auth && isAuthRoute) { const homeUrl = new URL("/", req.nextUrl.origin); return Response.redirect(homeUrl); } }); export const config = { matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"] };