Update-remaining-files
Some checks failed
CI / build-and-test (push) Failing after 1m50s
CI / deploy (push) Has been skipped

This commit is contained in:
SpecialX
2026-02-24 16:07:15 +08:00
parent a2e89ce795
commit ac859ee560
4 changed files with 17 additions and 3 deletions

View File

@@ -3,6 +3,12 @@ import type { NextAuthRequest } from "next-auth"
import { auth } from "./auth"
function normalizeRole(value: unknown) {
const role = String(value ?? "").trim().toLowerCase()
if (role === "admin" || role === "student" || role === "teacher" || role === "parent") return role
return "student"
}
function roleHome(role: string) {
if (role === "admin") return "/admin/dashboard"
if (role === "student") return "/student/dashboard"
@@ -21,7 +27,7 @@ export default auth((req: NextAuthRequest) => {
return NextResponse.redirect(url)
}
const role = String(session.user.role ?? "teacher")
const role = normalizeRole(session.user.role)
if (pathname.startsWith("/admin/") && role !== "admin") {
return NextResponse.redirect(new URL(roleHome(role), req.url))
@@ -42,4 +48,3 @@ export default auth((req: NextAuthRequest) => {
export const config = {
matcher: ["/dashboard", "/admin/:path*", "/teacher/:path*", "/student/:path*", "/parent/:path*", "/settings/:path*", "/profile"],
}