feat: 添加注册开关功能,优化系统配置与注册接口
ocs-nuxt / deploy (push) Failing after 11s

This commit is contained in:
2026-05-23 23:48:30 +08:00
parent bc785ac1ce
commit 5e99e28e8b
15 changed files with 371 additions and 48 deletions
+22
View File
@@ -0,0 +1,22 @@
// server/middleware/registration-guard.ts - 注册开关守卫
//
// 拦截 POST /api/auth/sign-up/email,若系统配置关闭了注册,立即返回 403。
// 此中间件优先于 Better Auth catch-all handler 执行,无需改动 auth.ts。
import { getRequestURL, setResponseStatus } from "h3";
import { apiErr } from "~~/server/utils/response";
import { getSysConfig } from "~~/server/utils/sysConfig";
export default defineEventHandler(async (event) => {
const { pathname } = getRequestURL(event);
// 只拦截注册接口
if (pathname !== "/api/auth/sign-up/email" || event.method !== "POST") return;
const cfg = await getSysConfig();
if (!cfg.allowRegistration) {
setResponseStatus(event, 403);
return apiErr(403, "当前未开启注册");
}
});