Initial role user app

This commit is contained in:
湛兮
2026-06-02 14:46:39 +08:00
commit 003dc60111
62 changed files with 7835 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import { NextRequest, NextResponse } from "next/server";
const protectedRoutes = ["/dashboard", "/tasks", "/schedule", "/announcements", "/store", "/me"];
const publicRoutes = ["/", "/login"];
const cookieName = process.env.ROLE_USER_SESSION_COOKIE || "role_user_session";
export function proxy(request: NextRequest) {
const path = request.nextUrl.pathname;
const hasSession = Boolean(request.cookies.get(cookieName)?.value);
const isProtected = protectedRoutes.some((route) => path === route || path.startsWith(`${route}/`));
const isPublic = publicRoutes.includes(path);
if (isProtected && !hasSession) {
return NextResponse.redirect(new URL("/login", request.url));
}
if (isPublic && hasSession) {
return NextResponse.redirect(new URL("/dashboard", request.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/((?!api|_next/static|_next/image|manifest.webmanifest|sw.js|.*\\..*).*)"]
};