Files
anxinyan/user-app/src/api/auth.ts
wushumin 9aac78b8da first
2026-05-11 15:28:27 +08:00

63 lines
1.4 KiB
TypeScript

import { request } from "../utils/request";
export interface AuthUserInfo {
id: number;
nickname: string;
mobile: string;
avatar: string;
status: string;
password_set: boolean;
}
export interface SendLoginCodeResult {
mobile: string;
scene: string;
expire_seconds: number;
retry_after_seconds: number;
debug_code?: string;
}
export interface LoginResult {
token: string;
user_info: AuthUserInfo;
}
export const authApi = {
sendLoginCode(mobile: string) {
return request<SendLoginCodeResult>("/api/app/auth/send-code", {
method: "POST",
data: { mobile },
});
},
loginByCode(mobile: string, code: string) {
return request<LoginResult>("/api/app/auth/login/code", {
method: "POST",
data: { mobile, code },
});
},
loginByPassword(mobile: string, password: string) {
return request<LoginResult>("/api/app/auth/login/password", {
method: "POST",
data: { mobile, password },
});
},
getMe() {
return request<{ user_info: AuthUserInfo }>("/api/app/auth/me");
},
savePassword(payload: {
current_password?: string;
new_password: string;
confirm_password: string;
}) {
return request<{ user_id: number; password_set: boolean; had_password: boolean }>("/api/app/auth/password/save", {
method: "POST",
data: payload,
});
},
logout() {
return request<Record<string, never>>("/api/app/auth/logout", {
method: "POST",
});
},
};