import { auth } from './auth'; import { NextResponse } from 'next/server'; export default auth((req) => { const { pathname } = req.nextUrl; if (pathname.startsWith('/admin')) { const role = (req.auth?.user as any)?.role; if (role !== 'admin') { const loginUrl = new URL('/login', req.url); loginUrl.searchParams.set('callbackUrl', pathname); return NextResponse.redirect(loginUrl); } } }); export const config = { matcher: ['/admin/:path*'], };