Admin panel for VinEye with dashboard, users, diseases, guides, alerts management. Stack: Next.js App Router + Prisma + PostgreSQL + better-auth. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
31 lines
733 B
TypeScript
31 lines
733 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
export async function middleware(request: NextRequest) {
|
|
const { pathname } = request.nextUrl;
|
|
|
|
if (
|
|
pathname.startsWith("/dashboard") ||
|
|
pathname.startsWith("/diseases") ||
|
|
pathname.startsWith("/guides") ||
|
|
pathname.startsWith("/users") ||
|
|
pathname.startsWith("/alerts")
|
|
) {
|
|
const sessionCookie = request.cookies.get("better-auth.session_token");
|
|
if (!sessionCookie) {
|
|
return NextResponse.redirect(new URL("/login", request.url));
|
|
}
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
matcher: [
|
|
"/dashboard/:path*",
|
|
"/diseases/:path*",
|
|
"/guides/:path*",
|
|
"/users/:path*",
|
|
"/alerts/:path*",
|
|
],
|
|
};
|