diff --git a/apps/frontend/lib/api/client.ts b/apps/frontend/lib/api/client.ts index 70130f6..319fcbe 100644 --- a/apps/frontend/lib/api/client.ts +++ b/apps/frontend/lib/api/client.ts @@ -46,4 +46,5 @@ export async function clientFetch( export * as AuthAPI from './endpoints/auth.client' -export * as UserAPI from './endpoints/user.client' \ No newline at end of file +export * as UserAPI from './endpoints/user.client' +export * as SmsAPI from './endpoints/sms.client' \ No newline at end of file diff --git a/apps/frontend/lib/api/endpoints/sms.client.ts b/apps/frontend/lib/api/endpoints/sms.client.ts new file mode 100644 index 0000000..4ae2336 --- /dev/null +++ b/apps/frontend/lib/api/endpoints/sms.client.ts @@ -0,0 +1,15 @@ +import { clientFetch } from "../client"; +import { APIError } from "../common"; + +export async function sendLoginSms(phone: string) { + phone = phone.trim(); + + if (!/^1[3-9]\d{9}$/.test(phone)) { + throw new APIError('请输入合法的中国大陆手机号'); + } + + return clientFetch('/api/sms/send/login', { + method: 'POST', + body: JSON.stringify({ phone }) + }) +} \ No newline at end of file