first
This commit is contained in:
62
user-app/src/api/auth.ts
Normal file
62
user-app/src/api/auth.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
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",
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user