迁移后端认证与拆分 Spacetime 客户端
This commit is contained in:
@@ -7,6 +7,8 @@ import type {
|
||||
AuthLoginMethod,
|
||||
AuthLoginOptionsResponse,
|
||||
AuthLogoutAllResponse,
|
||||
AuthPasswordChangeResponse,
|
||||
AuthPasswordResetResponse,
|
||||
AuthMeResponse,
|
||||
AuthPhoneChangeResponse,
|
||||
AuthPhoneLoginResponse,
|
||||
@@ -137,7 +139,7 @@ export function clearAuthSession() {
|
||||
|
||||
export async function sendPhoneLoginCode(
|
||||
phone: string,
|
||||
scene: 'login' | 'bind_phone' | 'change_phone' = 'login',
|
||||
scene: 'login' | 'bind_phone' | 'change_phone' | 'reset_password' = 'login',
|
||||
captcha?: {
|
||||
challengeId?: string;
|
||||
answer?: string;
|
||||
@@ -257,6 +259,50 @@ export async function authEntry(username: string, password: string) {
|
||||
return response.user;
|
||||
}
|
||||
|
||||
export async function changePassword(
|
||||
currentPassword: string,
|
||||
newPassword: string,
|
||||
) {
|
||||
const response = await requestJson<AuthPasswordChangeResponse>(
|
||||
'/api/auth/password/change',
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
currentPassword: currentPassword.trim() || undefined,
|
||||
newPassword: newPassword.trim(),
|
||||
}),
|
||||
},
|
||||
'修改密码失败',
|
||||
);
|
||||
|
||||
return response.user;
|
||||
}
|
||||
|
||||
export async function resetPassword(
|
||||
phone: string,
|
||||
code: string,
|
||||
newPassword: string,
|
||||
) {
|
||||
const response = await requestJson<AuthPasswordResetResponse>(
|
||||
'/api/auth/password/reset',
|
||||
{
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
phone: normalizePhoneInput(phone),
|
||||
code: code.trim(),
|
||||
newPassword: newPassword.trim(),
|
||||
}),
|
||||
},
|
||||
'重置密码失败',
|
||||
PUBLIC_AUTH_REQUEST_OPTIONS,
|
||||
);
|
||||
|
||||
setStoredAccessToken(response.token, { emit: false });
|
||||
return response.user;
|
||||
}
|
||||
|
||||
export async function authEntryWithStoredCredentials(
|
||||
credentials: AutoAuthCredentials,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user