first commit

This commit is contained in:
luoyangwei
2026-06-06 00:49:07 +08:00
commit 2b860d201e
134 changed files with 22773 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import { auth } from "@/lib/auth";
import { NextResponse } from "next/server";
export default auth((req) => {
const { nextUrl } = req;
const isLoggedIn = !!req.auth;
const isAdminRoute = nextUrl.pathname.startsWith("/admin");
const isLoginPage = nextUrl.pathname === "/admin/login";
// Only the admin login page is public. Everything else under /admin
// requires a NextAuth session.
if (isAdminRoute && !isLoggedIn && !isLoginPage) {
return NextResponse.redirect(new URL("/admin/login", nextUrl));
}
if (isLoggedIn && isLoginPage) {
return NextResponse.redirect(new URL("/admin/dashboard", nextUrl));
}
return NextResponse.next();
});
export const config = {
matcher: ["/admin/:path*"],
};