stage 1
This commit is contained in:
+26
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user