import { NextResponse } from 'next/server'; import { verifySession } from './lib/auth'; export const config = { matcher: [ '/dashboard/:path*', '/paper/:path*', '/dash/:path*', '/api/state', '/api/trades', '/api/reset' ], }; export async function middleware(req) { const token = req.cookies.get('kalbot_session')?.value; const isValid = await verifySession(token); if (!isValid) { if (req.nextUrl.pathname.startsWith('/api/')) { return NextResponse.json({ error: 'Unauthorized. Nice try!' }, { status: 401 }); } return NextResponse.redirect(new URL('/', req.url)); } return NextResponse.next(); }