blob: ee56360b9441a9ff46b6088f8755d35675946f9d [file] [log] [blame]
2230101462240ab2025-06-07 09:28:16 +08001import axios, { type AxiosResponse } from 'axios';
22301014b1477f72025-06-07 22:54:40 +08002import type { RejisterRequest , ResetPasswordRequest} from './type';
2230101462240ab2025-06-07 09:28:16 +08003import type{ LoginRequest } from './type';
22301014b1477f72025-06-07 22:54:40 +08004import type { CommonResponse } from '../type';
22301014bc4616f2025-06-03 16:59:44 +08005
22301014b1477f72025-06-07 22:54:40 +08006class AuthAPI {
22301014bc4616f2025-06-03 16:59:44 +08007
2230101462240ab2025-06-07 09:28:16 +08008 static sendVerificationCode(email: string): Promise<AxiosResponse<CommonResponse>> {
2230101433099002025-06-08 23:14:17 +08009 return axios.post('/api/auth/user/sendVerification', { email });
2230102371ee1c92025-06-05 16:18:32 +080010 }
11
2230101462240ab2025-06-07 09:28:16 +080012 static register(request: RejisterRequest): Promise<AxiosResponse<CommonResponse>> {
2230101433099002025-06-08 23:14:17 +080013 return axios.post('/api/auth/user/register', request);
2230101462240ab2025-06-07 09:28:16 +080014 }
2230102371ee1c92025-06-05 16:18:32 +080015
2230101462240ab2025-06-07 09:28:16 +080016 static sendResetCode(email: string):Promise<AxiosResponse<CommonResponse>> {
2230101433099002025-06-08 23:14:17 +080017 return axios.post('/api/auth/user/sendResetCode', { email });
2230102371ee1c92025-06-05 16:18:32 +080018 }
19
2230101462240ab2025-06-07 09:28:16 +080020 static resetPassword( request: ResetPasswordRequest ):Promise<AxiosResponse<CommonResponse>> {
2230101433099002025-06-08 23:14:17 +080021 return axios.post('/api/auth/user/resetPassword', request);
2230101462240ab2025-06-07 09:28:16 +080022 }
23
24
25 static refreshToken(oldToken : string): Promise<AxiosResponse<CommonResponse<string>>> {
26 return axios.post(
22301014b1477f72025-06-07 22:54:40 +080027 '/api/auth/refreshToken',
2230101462240ab2025-06-07 09:28:16 +080028 {}, // 请求体空
29 {
30 headers: {
31 token: oldToken,
32 },
33 }
34 );
35 }
36
37
38 static login(loginRequest: LoginRequest): Promise<AxiosResponse<CommonResponse<string>>> {
2230101433099002025-06-08 23:14:17 +080039 return axios.post('/api/auth/user/login', loginRequest);
2230101462240ab2025-06-07 09:28:16 +080040 }
2230102371ee1c92025-06-05 16:18:32 +080041
42}
43
22301014b1477f72025-06-07 22:54:40 +080044export default AuthAPI;
22301014bc4616f2025-06-03 16:59:44 +080045