|
|
@@ -49,7 +49,7 @@ interface ApiResponse {
|
|
|
data?: any;
|
|
|
}
|
|
|
|
|
|
-let token: string = '';
|
|
|
+let token: string = localStorage.getItem('api_token') || '';
|
|
|
let currentUserInfo: UserInfo | null = null;
|
|
|
|
|
|
const apiClient = axios.create({
|
|
|
@@ -62,8 +62,9 @@ const apiClient = axios.create({
|
|
|
|
|
|
apiClient.interceptors.request.use(
|
|
|
(config) => {
|
|
|
- if (token) {
|
|
|
- config.headers['token'] = token;
|
|
|
+ const currentToken = token || localStorage.getItem('api_token') || '';
|
|
|
+ if (currentToken) {
|
|
|
+ config.headers['token'] = currentToken;
|
|
|
}
|
|
|
return config;
|
|
|
},
|
|
|
@@ -92,6 +93,7 @@ async function login(authCode: string): Promise<UserInfo> {
|
|
|
|
|
|
if (response.data.code === 200) {
|
|
|
token = response.data.result.token;
|
|
|
+ localStorage.setItem('api_token', token);
|
|
|
const userInfoStr = response.data.result.user_info;
|
|
|
try {
|
|
|
const parsedUserInfo = JSON.parse(userInfoStr);
|