You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

24 lines
945 B

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<string, unknown>;
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: "请完成验证码" });
}
}