18 lines
351 B
TypeScript
18 lines
351 B
TypeScript
import { auth } from "@/app/(auth)/auth";
|
|
import { ChatSDKError } from "@/lib/errors";
|
|
|
|
export async function requireAdmin() {
|
|
const session = await auth();
|
|
|
|
if (!session?.user) {
|
|
throw new ChatSDKError("unauthorized:admin");
|
|
}
|
|
|
|
if (session.user.type !== "admin") {
|
|
throw new ChatSDKError("forbidden:admin");
|
|
}
|
|
|
|
return session;
|
|
}
|
|
|