chore: 给phone登陆改成sms登陆,并顺手实现sms登陆

This commit is contained in:
2025-12-17 23:23:14 +08:00
parent 0575f892ef
commit 4569d6e443
4 changed files with 110 additions and 72 deletions

View File

@@ -24,4 +24,29 @@ export async function loginByPassword(identifier: string, password: string) {
password,
})
});
}
export async function loginBySms(phone: string, code: string) {
phone = phone.trim();
code = code.trim();
if (phone.length === 0 || code.length === 0) {
throw new APIError('请输入手机号及短信验证码')
}
if (!/^1[3-9]\d{9}$/.test(phone)) {
throw new APIError('请输入合法的中国大陆手机号');
}
if (! /\d{6}/.test(code)) {
throw new APIError('密码长度只能为6~32位')
}
return clientFetch<{ user: User }>('/api/auth/login/sms', {
method: 'POST',
body: JSON.stringify({
phone,
code,
})
});
}