2026-01-06 09:24:25 +00:00
|
|
|
import { NextResponse } from "next/server";
|
2026-01-08 05:41:31 +00:00
|
|
|
import {auth} from "@/auth";
|
2026-01-06 09:24:25 +00:00
|
|
|
|
|
|
|
|
const protectedRoutes = ["/dashboard", "/profile"];
|
|
|
|
|
const apiAuthPrefix = "/api/auth";
|
|
|
|
|
|
|
|
|
|
export const proxy = auth((req) => {
|
|
|
|
|
const { nextUrl } = req;
|
|
|
|
|
const isLoggedIn = !!req.auth;
|
|
|
|
|
|
|
|
|
|
const path = nextUrl.pathname;
|
|
|
|
|
const isApiAuthRoute = path.startsWith(apiAuthPrefix);
|
|
|
|
|
const isProtectedRoute = protectedRoutes.includes(path);
|
|
|
|
|
|
|
|
|
|
// 1. Allow API Auth calls (Login/Logout/Callback)
|
|
|
|
|
if (isApiAuthRoute) {
|
|
|
|
|
return NextResponse.next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. CHANGED: Redirect to HOME (/) instead of /login if logged out
|
|
|
|
|
if (isProtectedRoute && !isLoggedIn) {
|
|
|
|
|
return NextResponse.redirect(new URL("/", nextUrl));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NextResponse.next();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const config = {
|
|
|
|
|
matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"],
|
|
|
|
|
};
|