export type AuthCredentialsAndCaptcha = { username: string; password: string; captchaId: string; captchaAnswer: string; }; export function assertLoginRegisterCaptchaFieldsPresent( body: unknown, ): asserts body is AuthCredentialsAndCaptcha { if (typeof body !== "object" || body === null) { throw createError({ statusCode: 400, statusMessage: "无效请求" }); } const b = body as Record; if (typeof b.username !== "string" || typeof b.password !== "string") { throw createError({ statusCode: 400, statusMessage: "无效请求" }); } if (typeof b.captchaId !== "string" || b.captchaId.trim() === "") { throw createError({ statusCode: 400, statusMessage: "请完成验证码" }); } if (typeof b.captchaAnswer !== "string" || b.captchaAnswer.trim() === "") { throw createError({ statusCode: 400, statusMessage: "请完成验证码" }); } }