blob: 4a08c2dd7470a251811ac539cd475e01131ca127 [file] [log] [blame]
2230101462240ab2025-06-07 09:28:16 +08001import axios, { type AxiosResponse } from 'axios';
2import type { RejisterRequest , CommonResponse, ResetPasswordRequest} from './type';
3import type{ LoginRequest } from './type';
22301014bc4616f2025-06-03 16:59:44 +08004
2230101462240ab2025-06-07 09:28:16 +08005class authAPI {
22301014bc4616f2025-06-03 16:59:44 +08006
2230101462240ab2025-06-07 09:28:16 +08007 static sendVerificationCode(email: string): Promise<AxiosResponse<CommonResponse>> {
2230102371ee1c92025-06-05 16:18:32 +08008 return axios.post('/api/sendVerification', { email });
9 }
10
2230101462240ab2025-06-07 09:28:16 +080011 static register(request: RejisterRequest): Promise<AxiosResponse<CommonResponse>> {
12 return axios.post('/api/register', request);
13 }
2230102371ee1c92025-06-05 16:18:32 +080014
2230101462240ab2025-06-07 09:28:16 +080015 static sendResetCode(email: string):Promise<AxiosResponse<CommonResponse>> {
2230102371ee1c92025-06-05 16:18:32 +080016 return axios.post('/api/sendResetCode', { email });
17 }
18
2230101462240ab2025-06-07 09:28:16 +080019 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 }
2230102371ee1c92025-06-05 16:18:32 +080040
41}
42
43export default authAPI;
22301014bc4616f2025-06-03 16:59:44 +080044