feat: initial admin panel

This commit is contained in:
2026-02-19 22:13:11 +03:30
parent 70efff0dfd
commit 9aff48019d
50 changed files with 9604 additions and 1 deletions
+30
View File
@@ -0,0 +1,30 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
const token = request.cookies.get('auth_token')?.value ||
request.headers.get('authorization')?.replace('Bearer ', '');
const isAdminRoute = request.nextUrl.pathname.startsWith('/admin');
const isLoginRoute = request.nextUrl.pathname === '/admin/login';
// Allow access to login page without token
if (isLoginRoute) {
// If already logged in, redirect to dashboard
if (token) {
return NextResponse.redirect(new URL('/admin/dashboard', request.url));
}
return NextResponse.next();
}
// Protect admin routes
if (isAdminRoute && !token) {
return NextResponse.redirect(new URL('/admin/login', request.url));
}
return NextResponse.next();
}
export const config = {
matcher: '/admin/:path*',
};