diff --git a/apps/frontend/lib/api/endpoints/auth.client.ts b/apps/frontend/lib/api/endpoints/auth.client.ts index 7288044..3a58511 100644 --- a/apps/frontend/lib/api/endpoints/auth.client.ts +++ b/apps/frontend/lib/api/endpoints/auth.client.ts @@ -49,4 +49,8 @@ export async function loginBySms(phone: string, code: string) { code, }) }); +} + +export async function logout() { + return clientFetch('/api/auth/logout', { method: 'POST' }); } \ No newline at end of file diff --git a/apps/frontend/lib/api/endpoints/user.client.ts b/apps/frontend/lib/api/endpoints/user.client.ts index 84d9cd4..d20fdb1 100644 --- a/apps/frontend/lib/api/endpoints/user.client.ts +++ b/apps/frontend/lib/api/endpoints/user.client.ts @@ -1,6 +1,20 @@ import { User } from "@/lib/types/user"; import { clientFetch } from "../client"; +import { APIError } from "../common"; export async function me() { return clientFetch('/api/user/me'); +} + +export async function updatePassword(password: string) { + if (! /^(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d!@#$%^&*()_+\-=\[\]{};:'",.<>/?]{6,32}$/.test(password)) { + throw new APIError('新密码不符合规范,请重新输入') + } + + return clientFetch('/api/user/password', { + method: 'PUT', + body: JSON.stringify({ + password, + }), + }) } \ No newline at end of file