sync-docs-and-fixes
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
import { redirect } from "next/navigation"
|
||||
import { auth } from "@/auth"
|
||||
import { getUserProfile } from "@/modules/users/data-access"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
const normalizeRole = (value: unknown) => {
|
||||
const role = String(value ?? "").trim().toLowerCase()
|
||||
if (role === "admin" || role === "student" || role === "teacher" || role === "parent") return role
|
||||
return "student"
|
||||
}
|
||||
|
||||
export default async function DashboardPage() {
|
||||
const session = await auth()
|
||||
if (!session?.user) redirect("/login")
|
||||
|
||||
const role = normalizeRole(session.user.role)
|
||||
const userId = String(session.user.id ?? "").trim()
|
||||
if (!userId) redirect("/login")
|
||||
const profile = await getUserProfile(userId)
|
||||
if (!profile) redirect("/login")
|
||||
const role = profile.role || "student"
|
||||
|
||||
if (role === "admin") redirect("/admin/dashboard")
|
||||
if (role === "student") redirect("/student/dashboard")
|
||||
|
||||
Reference in New Issue
Block a user