mirror of
https://github.com/JetSprow/J-Board-Lite.git
synced 2026-05-01 01:14:10 +05:30
Initial commit
This commit is contained in:
18
src/lib/require-auth.ts
Normal file
18
src/lib/require-auth.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { getServerSession } from "next-auth";
|
||||
import { authOptions } from "./auth";
|
||||
|
||||
export async function requireAdmin() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session || session.user.role !== "ADMIN") {
|
||||
throw new Error("无权限");
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
export async function requireAuth() {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session) {
|
||||
throw new Error("未登录");
|
||||
}
|
||||
return session;
|
||||
}
|
||||
Reference in New Issue
Block a user