import { NextResponse } from "next/server"; import type { NextRequest } from "next/server"; import { SESSION_COOKIE_NAME, verifySessionToken } from "./lib/auth"; export async function middleware(req: NextRequest) { const token = req.cookies.get(SESSION_COOKIE_NAME)?.value; const session = token ? await verifySessionToken(token) : null; if (!session) { const loginUrl = new URL("/login", req.url); return NextResponse.redirect(loginUrl); } return NextResponse.next(); } export const config = { matcher: [ "/dashboard/:path*", // Match all /api/files routes EXCEPT /api/files/upload (which handles large bodies) "/api/files/list", "/api/files/delete-all", "/api/files/:id/download", "/api/files/:id/delete", ], };