15 lines
447 B
TypeScript
15 lines
447 B
TypeScript
import { getCurrentUser } from "@/lib/user";
|
|
import { redirect } from "next/navigation";
|
|
import { AppError } from "@/lib/action-result";
|
|
|
|
export async function requireUser() {
|
|
const user = await getCurrentUser();
|
|
if (!user) redirect("/");
|
|
return user;
|
|
}
|
|
|
|
export async function requireAdmin() {
|
|
const user = await requireUser();
|
|
if (!user.isAdmin) throw new AppError("You do not have permission to perform this action.");
|
|
return user;
|
|
} |