22301014 | 62240ab | 2025-06-07 09:28:16 +0800 | [diff] [blame^] | 1 | import axios, { type AxiosResponse } from 'axios'; |
| 2 | import type { RejisterRequest , CommonResponse, ResetPasswordRequest} from './type'; |
| 3 | import type{ LoginRequest } from './type'; |
22301014 | bc4616f | 2025-06-03 16:59:44 +0800 | [diff] [blame] | 4 | |
22301014 | 62240ab | 2025-06-07 09:28:16 +0800 | [diff] [blame^] | 5 | class authAPI { |
22301014 | bc4616f | 2025-06-03 16:59:44 +0800 | [diff] [blame] | 6 | |
22301014 | 62240ab | 2025-06-07 09:28:16 +0800 | [diff] [blame^] | 7 | static sendVerificationCode(email: string): Promise<AxiosResponse<CommonResponse>> { |
22301023 | 71ee1c9 | 2025-06-05 16:18:32 +0800 | [diff] [blame] | 8 | return axios.post('/api/sendVerification', { email }); |
| 9 | } |
| 10 | |
22301014 | 62240ab | 2025-06-07 09:28:16 +0800 | [diff] [blame^] | 11 | static register(request: RejisterRequest): Promise<AxiosResponse<CommonResponse>> { |
| 12 | return axios.post('/api/register', request); |
| 13 | } |
22301023 | 71ee1c9 | 2025-06-05 16:18:32 +0800 | [diff] [blame] | 14 | |
22301014 | 62240ab | 2025-06-07 09:28:16 +0800 | [diff] [blame^] | 15 | static sendResetCode(email: string):Promise<AxiosResponse<CommonResponse>> { |
22301023 | 71ee1c9 | 2025-06-05 16:18:32 +0800 | [diff] [blame] | 16 | return axios.post('/api/sendResetCode', { email }); |
| 17 | } |
| 18 | |
22301014 | 62240ab | 2025-06-07 09:28:16 +0800 | [diff] [blame^] | 19 | static resetPassword( request: ResetPasswordRequest ):Promise<AxiosResponse<CommonResponse>> { |
| 20 | return axios.post('/api/resetPassword', request); |
| 21 | } |
| 22 | |
| 23 | |
| 24 | static refreshToken(oldToken : string): Promise<AxiosResponse<CommonResponse<string>>> { |
| 25 | return axios.post( |
| 26 | '/api/refreshToken', |
| 27 | {}, // 请求体空 |
| 28 | { |
| 29 | headers: { |
| 30 | token: oldToken, |
| 31 | }, |
| 32 | } |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | static login(loginRequest: LoginRequest): Promise<AxiosResponse<CommonResponse<string>>> { |
| 38 | return axios.post('/api/login', loginRequest); |
| 39 | } |
22301023 | 71ee1c9 | 2025-06-05 16:18:32 +0800 | [diff] [blame] | 40 | |
| 41 | } |
| 42 | |
| 43 | export default authAPI; |
22301014 | bc4616f | 2025-06-03 16:59:44 +0800 | [diff] [blame] | 44 | |