mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-16 21:41:02 +00:00
28 lines
657 B
JavaScript
28 lines
657 B
JavaScript
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();
|
|
}
|