import { NextResponse } from "next/server"; import type { NextRequest } from "next/server"; import { getToken } from "next-auth/jwt"; export async function middleware(req: NextRequest) { const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET }); if (req.nextUrl.pathname.startsWith("/admin") && !token) { const url = req.nextUrl.clone(); url.pathname = "/login"; return NextResponse.redirect(url); } return NextResponse.next(); } export const config = { matcher: [ "/admin/:path*", "/api/delete/downloads/[id]", "/api/delete/logs/[id]", "/api/delete/mods/[id]", "/api/upload", "/api/uploadlogs", "/api/uploadmods", "/api/uploadthing", ], };