import type { NextRequest } from 'next/server' import { getSessionCookie } from 'better-auth/cookies' import { NextResponse } from 'next/server' const PUBLIC_PATHS = ['/admin/login', '/admin/forgot-password', '/admin/reset-password'] /** * Optimistic cookie check only — it never validates the session. `requireRole()` in the * `(authenticated)` gate and in every Server Action remains the authorization boundary. */ export function proxy(request: NextRequest) { if (PUBLIC_PATHS.includes(request.nextUrl.pathname) || getSessionCookie(request)) { return NextResponse.next() } return NextResponse.redirect(new URL('/admin/login', request.url)) } export const config = { matcher: ['/admin', '/admin/:path*'] }