diff --git a/server/api/auth/register.post.ts b/server/api/auth/register.post.ts index 4d420a6..f7b5c5a 100644 --- a/server/api/auth/register.post.ts +++ b/server/api/auth/register.post.ts @@ -12,13 +12,14 @@ export default defineWrappedResponseHandler(async (event) => { const parsed = registerSchema.safeParse(body) if (!parsed.success) { - return R.error(parsed.error.issues[0]?.message || '表单验证失败', null) + const field = parsed.error.issues[0]?.path[0]?.toString() ?? undefined + return R.error(parsed.error.issues[0]?.message || '表单验证失败', { field }) } const { username, password, captchaToken, captchaText } = parsed.data if (!verifyCaptcha(captchaToken, captchaText)) { - return R.error('验证码错误或已过期', null) + return R.error('验证码错误或已过期', { field: 'captchaText' }) } const hashedPassword = await hash(password, 10) @@ -38,7 +39,7 @@ export default defineWrappedResponseHandler(async (event) => { } catch (err: any) { const msg = String(err?.message ?? '') if (msg.toLowerCase().includes('unique') || msg.includes('SQLITE_CONSTRAINT')) { - return R.error('用户名已存在', null) + return R.error('用户名已存在', { field: 'username' }) } logger.error('Failed to insert user', msg) return R.error('注册失败,请稍后重试', null)