mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-17 05:51:02 +00:00
31 lines
729 B
JavaScript
31 lines
729 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',
|
|
'/api/live-state',
|
|
'/api/live-trades',
|
|
'/api/live-toggle',
|
|
],
|
|
};
|
|
|
|
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();
|
|
}
|