27 lines
756 B
TypeScript
27 lines
756 B
TypeScript
import { redirect } from "next/navigation";
|
|
import { getSessionUser, type SessionUser } from "@/lib/session";
|
|
|
|
export async function getCurrentUser(): Promise<SessionUser | null> {
|
|
return getSessionUser();
|
|
}
|
|
|
|
export async function requireUser(): Promise<SessionUser> {
|
|
const user = await getSessionUser();
|
|
if (!user) redirect("/login");
|
|
return user;
|
|
}
|
|
|
|
export async function requireAdmin(): Promise<SessionUser> {
|
|
const user = await getSessionUser();
|
|
if (!user) redirect("/login");
|
|
if (user.role !== "admin") redirect("/");
|
|
return user;
|
|
}
|
|
|
|
export async function requireOperator(): Promise<SessionUser> {
|
|
const user = await getSessionUser();
|
|
if (!user) redirect("/login");
|
|
if (user.role !== "operator") redirect("/");
|
|
return user;
|
|
}
|