feat: harden bootstrap and add tests

This commit is contained in:
2026-06-28 16:43:03 -05:00
parent 01ea9e391d
commit 991e73fcff
39 changed files with 3399 additions and 459 deletions
+40
View File
@@ -0,0 +1,40 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
// Simple middleware for Next.js Edge Runtime
// This is a basic implementation that doesn't verify tokens
// In a production environment, you would want to verify the token
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
// Protect admin routes
if (pathname.startsWith('/admin')) {
// Get session token from cookies
const token = request.cookies.get('session')?.value;
// If no token, redirect to login
if (!token) {
return NextResponse.redirect(new URL('/login', request.url));
}
// Note: In a real implementation, you would verify the token here
// For now, we're just checking that a token exists
}
// Redirect authenticated users from login page to home
if (pathname === '/login') {
const token = request.cookies.get('session')?.value;
if (token) {
// In a real implementation, you would verify the token and check role
// For now, we'll just redirect to home
return NextResponse.redirect(new URL('/', request.url));
}
}
return NextResponse.next();
}
// Configure which paths the middleware should run on
export const config = {
matcher: ['/admin/:path*', '/login'],
};