完善验证页面和后端接口的链接
> 1. 配置了开发环境的端口转发 -> localhost:8080\
> 2. 完成了注册,登录,忘记密码页的功能
> 3. 为项目配置了vitest测试框架
> 4. 对这三个页面进行了测试
> 重写了/test/setup.ts
Change-Id: I46c600ce06d698dae6953b2e1e3ff4a98b0f3de4
diff --git a/src/api/authApi.ts b/src/api/authApi.ts
index 3a8eb17..4a08c2d 100644
--- a/src/api/authApi.ts
+++ b/src/api/authApi.ts
@@ -1,78 +1,42 @@
-import axios from 'axios';
+import axios, { type AxiosResponse } from 'axios';
+import type { RejisterRequest , CommonResponse, ResetPasswordRequest} from './type';
+import type{ LoginRequest } from './type';
+class authAPI {
- class authAPI {
-
- // static getUserById(userId) {
- // // 例如 GET http://localhost:8080/123
- // return axios.get(`/${userId}`);
- // }
-
-
- // static updateUser(userId, data) {
- // // 例如 PUT http://localhost:8080/123 Body: { username: 'xxx', ... }
- // return axios.put(`/${userId}`, data);
- // }
- //
- //
- // static deleteUser(userId:string) {
- // // 例如 DELETE http://localhost:8080/123
- // return axios.delete(`/${userId}`);
- // }
-
-
- static sendVerificationCode(email: string) {
- // Body: { email: 'xxx@yyy.com'}
+ static sendVerificationCode(email: string): Promise<AxiosResponse<CommonResponse>> {
return axios.post('/api/sendVerification', { email });
}
+ static register(request: RejisterRequest): Promise<AxiosResponse<CommonResponse>> {
+ return axios.post('/api/register', request);
+ }
- static sendResetCode(email: string) {
- // Body: { email: 'xxx@yyy.com' }
+ static sendResetCode(email: string):Promise<AxiosResponse<CommonResponse>> {
return axios.post('/api/sendResetCode', { email });
}
- //
- // static resetPassword({ email, code, newPassword }) {
- // // Body: { email, code, newPassword }
- // return axios.post('/resetPassword', { email, code, newPassword });
- // }
- //
- //
- // static register({ username, email, verificationCode, password }) {
- // // Body: { username, email, verificationCode, password, identificationNumber? }
- // const body = {
- // username,
- // email,
- // verificationCode,
- // password,
- // };
- // return axios.post('/register', body);
- // }
- //
- // /**
- // * 刷新 JWT Token(POST /refreshToken)
- // * @param {string} oldToken 旧的 JWT(放在 header: token)
- // * @returns {Promise<AxiosResponse>}
- // */
- // static refreshToken(oldToken : string) {
- // // 因为后端是从 header 中读取旧 token,这里直接把 token 放进 headers
- // return axios.post(
- // '/refreshToken',
- // {}, // 请求体空
- // {
- // headers: {
- // token: oldToken,
- // },
- // }
- // );
- // }
- //
- //
- // static login({ email, password } : {email: string, password:string}) {
- // // Body: { email, password }
- // return axios.post('/login', { email, password });
- // }
+ static resetPassword( request: ResetPasswordRequest ):Promise<AxiosResponse<CommonResponse>> {
+ return axios.post('/api/resetPassword', request);
+ }
+
+
+ static refreshToken(oldToken : string): Promise<AxiosResponse<CommonResponse<string>>> {
+ return axios.post(
+ '/api/refreshToken',
+ {}, // 请求体空
+ {
+ headers: {
+ token: oldToken,
+ },
+ }
+ );
+ }
+
+
+ static login(loginRequest: LoginRequest): Promise<AxiosResponse<CommonResponse<string>>> {
+ return axios.post('/api/login', loginRequest);
+ }
}