完成顶部导航条
> 添加左侧logo
> 添加右侧用户信息展示
> 修复一些登录注册的跳转问题
> 修复axios拦截器错误的头设置
> 修复authApi错误的接口路径
> 组织api文件结构
Change-Id: Ifaec7e9a78ad6862ce7d0ce76be5181185186edd
diff --git a/src/feature/auth/authSlice.ts b/src/feature/auth/authSlice.ts
index f1ab2a0..607a6fd 100644
--- a/src/feature/auth/authSlice.ts
+++ b/src/feature/auth/authSlice.ts
@@ -1,11 +1,13 @@
import { createAsyncThunk, createSlice, type PayloadAction } from "@reduxjs/toolkit";
import type { AuthState } from "../../store/types";
-import type { LoginRequest } from "../../api/type";
-import authAPI from "../../api/authApi";
+import type { LoginRequest } from "../../api/Auth/type";
+import AuthAPI from "../../api/Auth/AuthApi";
+// 获取本地存储的 token
+const storedToken = localStorage.getItem('token');
const initialState: AuthState = {
- token: '',
+ token: storedToken || '',
loading: false,
isAuth: false,
error: ''
@@ -19,7 +21,7 @@
'auth/login',
async (loginRequest: LoginRequest, { rejectWithValue }) => {
try {
- const response = await authAPI.login(loginRequest);
+ const response = await AuthAPI.login(loginRequest);
if(response.data.code == 0) {
return {token: response.data.data};
}
@@ -40,7 +42,8 @@
'auth/refresh',
async (oldToken: string, { rejectWithValue }) => {
try {
- const response = await authAPI.refreshToken(oldToken);
+ const response = await AuthAPI.refreshToken(oldToken);
+ console.log(response);
if(response.data.code == 0)
return {token: response.data.data};
else
@@ -94,5 +97,6 @@
},
});
-
+
+export const { logout } = authSlice.actions;
export default authSlice.reducer;
\ No newline at end of file