create a comprehensive admin dashbioard with permalink /admin/ and creat

This commit is contained in:
Leon Serfaty G
2025-07-17 10:40:28 +00:00
parent d6e45f10e4
commit a1f3e2b3f5
5 changed files with 246 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
import {NextResponse} from 'next/server';
import type {NextRequest} from 'next/server';
export function middleware(request: NextRequest) {
const session = request.cookies.get('session');
// Redirect to login if trying to access /admin without a session
if (request.nextUrl.pathname.startsWith('/admin') && !session) {
return NextResponse.redirect(new URL('/login', request.url));
}
// Redirect to admin if trying to access /login with a session
if (request.nextUrl.pathname === '/login' && session) {
return NextResponse.redirect(new URL('/admin', request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ['/admin/:path*', '/login'],
};