| 1 | import type { AuthRequestOptions, CodeLoginResponse, EmailCodeLoginParams, GoogleLoginParams, LoginResponse, PhoneCodeLoginParams, SendEmailCodeParams, SendPhoneCodeParams, UpdateUserInfoParams } from './auth.types' |
| 2 | import type { UserInfo } from '@/store/user' |
| 3 | import type { RequestOptions } from '@/utils/request' |
| 4 | import http from '@/utils/request' |
| 5 | |
| 6 | /** 发送邮箱验证码 */ |
| 7 | export function sendEmailCodeApi(data: SendEmailCodeParams) { |
| 8 | return http.post<null>('login/mail', data) |
| 9 | } |
| 10 | |
| 11 | /** 邮箱验证码登录 */ |
| 12 | export function emailCodeLoginApi(data: EmailCodeLoginParams) { |
| 13 | return http.post<CodeLoginResponse>('login/mail/verify', data) |
| 14 | } |
| 15 | |
| 16 | /** 发送手机验证码 */ |
| 17 | export function sendPhoneCodeApi(data: SendPhoneCodeParams) { |
| 18 | return http.post<null>('login/phone', data) |
| 19 | } |
| 20 | |
| 21 | /** 手机验证码登录 */ |
| 22 | export function phoneCodeLoginApi(data: PhoneCodeLoginParams) { |
| 23 | return http.post<CodeLoginResponse>('login/phone/verify', data) |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Get Current User Information |
| 28 | * Retrieve the profile of the authenticated user. |
| 29 | */ |
| 30 | export function getUserInfoApi(options?: RequestOptions & AuthRequestOptions) { |
| 31 | const { silent, ...requestOptions } = options ?? {} |
| 32 | return http.get<UserInfo>('user/mine', undefined, silent, requestOptions) |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Update User Information |
| 37 | * Update the profile of the authenticated user. |
| 38 | */ |
| 39 | export function updateUserInfoApi(data: UpdateUserInfoParams) { |
| 40 | return http.put<UserInfo>('user/info/update', data) |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Google 登录 |
| 45 | * 使用 Google 凭证登录用户。 |
| 46 | */ |
| 47 | export function googleLoginApi(data: GoogleLoginParams) { |
| 48 | return http.post<LoginResponse>('login/google', data) |
| 49 | } |
| 50 |