25 lines
879 B
TypeScript
25 lines
879 B
TypeScript
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;
|
|
const token = request.cookies.get('session')?.value;
|
|
|
|
// Protect admin routes - let page handle auth UI
|
|
// No redirect here; the admin page shows login prompt if not authenticated
|
|
|
|
// If logged in and trying to access login, redirect to admin
|
|
if (pathname === '/login' && token) {
|
|
return NextResponse.redirect(new URL('/admin', request.url));
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
// Configure which paths the middleware should run on
|
|
export const config = {
|
|
matcher: ['/admin/:path*', '/login'],
|
|
}; |