feat: /api/config endpoint can be called using APIKey

This commit is contained in:
beilunyang
2025-05-13 00:01:15 +08:00
parent fa1dadfb21
commit eb6c3fe5eb
3 changed files with 16 additions and 5 deletions
+5 -3
View File
@@ -10,6 +10,7 @@ import CredentialsProvider from "next-auth/providers/credentials"
import { hashPassword, comparePassword } from "@/lib/utils"
import { authSchema } from "@/lib/validation"
import { generateAvatarUrl } from "./avatar"
import { getUserId } from "./apiKey"
const ROLE_DESCRIPTIONS: Record<Role, string> = {
[ROLES.EMPEROR]: "皇帝(网站所有者)",
@@ -62,12 +63,13 @@ export async function getUserRole(userId: string) {
}
export async function checkPermission(permission: Permission) {
const session = await auth()
if (!session?.user?.id) return false
const userId = await getUserId()
if (!userId) return false
const db = createDb()
const userRoleRecords = await db.query.userRoles.findMany({
where: eq(userRoles.userId, session.user.id),
where: eq(userRoles.userId, userId),
with: { role: true },
})