47 lines
981 B
TypeScript
47 lines
981 B
TypeScript
import { apiClient } from './client'
|
|
|
|
export interface AuthUser {
|
|
id: number
|
|
phone: string
|
|
nickname: string
|
|
realname_status: string
|
|
risk_status: string
|
|
credit_score: number
|
|
status: string
|
|
}
|
|
|
|
export interface TokenPair {
|
|
access_token: string
|
|
refresh_token: string
|
|
token_type: string
|
|
expires_in: number
|
|
}
|
|
|
|
export interface LoginData {
|
|
user: AuthUser
|
|
tokens: TokenPair
|
|
}
|
|
|
|
interface ApiResponse<T> {
|
|
code: string
|
|
message: string
|
|
data: T
|
|
}
|
|
|
|
export async function sendSmsCode(phone: string) {
|
|
const { data } = await apiClient.post<ApiResponse<{ phone: string; expires_in: number }>>('/auth/sms/send', {
|
|
phone,
|
|
})
|
|
return data.data
|
|
}
|
|
|
|
export async function loginWithSms(phone: string, code: string) {
|
|
const { data } = await apiClient.post<ApiResponse<LoginData>>('/auth/sms/login', { phone, code })
|
|
return data.data
|
|
}
|
|
|
|
export async function fetchMe() {
|
|
const { data } = await apiClient.get<ApiResponse<AuthUser>>('/me')
|
|
return data.data
|
|
}
|