mirror of
https://github.com/multipleof4/KalBot.git
synced 2026-03-17 05:51:02 +00:00
Feat: Protect /paper and /dash routes
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { verifySession } from './lib/auth';
|
import { verifySession } from './lib/auth';
|
||||||
|
|
||||||
// Define which paths should trigger this middleware
|
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: [
|
matcher: [
|
||||||
'/dashboard/:path*',
|
'/dashboard/:path*',
|
||||||
|
'/paper/:path*',
|
||||||
|
'/dash/:path*',
|
||||||
'/api/state',
|
'/api/state',
|
||||||
'/api/trades'
|
'/api/trades'
|
||||||
],
|
],
|
||||||
@@ -15,15 +16,11 @@ export async function middleware(req) {
|
|||||||
const isValid = await verifySession(token);
|
const isValid = await verifySession(token);
|
||||||
|
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
// If they are trying to hit an API endpoint without a session, return 401
|
|
||||||
if (req.nextUrl.pathname.startsWith('/api/')) {
|
if (req.nextUrl.pathname.startsWith('/api/')) {
|
||||||
return NextResponse.json({ error: 'Unauthorized. Nice try!' }, { status: 401 });
|
return NextResponse.json({ error: 'Unauthorized. Nice try!' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, boot them back to the login page
|
|
||||||
return NextResponse.redirect(new URL('/', req.url));
|
return NextResponse.redirect(new URL('/', req.url));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Session is valid, allow the request to proceed
|
|
||||||
return NextResponse.next();
|
return NextResponse.next();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user