Add admin dashboard and middleware protection
Introduces an admin dashboard page with cards for inviting vendors, banning users, and viewing recent orders. Adds middleware logic to restrict /admin routes to the 'admin1' user and updates route matching. Also updates git-info.json with latest commit metadata.
This commit is contained in:
@@ -52,7 +52,23 @@ export async function middleware(req: NextRequest) {
|
||||
return NextResponse.redirect(new URL("/auth/login", req.url));
|
||||
}
|
||||
|
||||
console.log("Middleware: Auth check successful, proceeding to dashboard");
|
||||
console.log("Middleware: Auth check successful");
|
||||
|
||||
// Admin-only protection for /admin routes
|
||||
const pathname = new URL(req.url).pathname;
|
||||
if (pathname.startsWith('/admin')) {
|
||||
try {
|
||||
const user = await res.json();
|
||||
const username = user?.vendor?.username;
|
||||
if (username !== 'admin1') {
|
||||
console.log("Middleware: Non-admin attempted to access /admin, redirecting");
|
||||
return NextResponse.redirect(new URL("/dashboard", req.url));
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Middleware: Failed to parse user for admin check, redirecting to login");
|
||||
return NextResponse.redirect(new URL("/auth/login", req.url));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Authentication validation failed:", error);
|
||||
return NextResponse.redirect(new URL("/auth/login", req.url));
|
||||
@@ -62,5 +78,5 @@ export async function middleware(req: NextRequest) {
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ["/dashboard/:path*"],
|
||||
matcher: ["/dashboard/:path*", "/admin/:path*"],
|
||||
};
|
||||
Reference in New Issue
Block a user