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