mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): new storage system [新的本地数据存储系统]
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import type { AxiosRequestConfig } from 'axios';
|
||||
import { useAuthStore } from '@/store';
|
||||
import { getRefreshToken, setRefreshToken, setToken } from '@/utils';
|
||||
import { localStg } from '@/utils';
|
||||
import { fetchUpdateToken } from '../api';
|
||||
|
||||
/**
|
||||
@ -9,11 +9,12 @@ import { fetchUpdateToken } from '../api';
|
||||
*/
|
||||
export async function handleRefreshToken(axiosConfig: AxiosRequestConfig) {
|
||||
const { resetAuthStore } = useAuthStore();
|
||||
const refreshToken = getRefreshToken();
|
||||
const refreshToken = localStg.get('refreshToken') || '';
|
||||
const { data } = await fetchUpdateToken(refreshToken);
|
||||
if (data) {
|
||||
setToken(data.token);
|
||||
setRefreshToken(data.refreshToken);
|
||||
localStg.set('token', data.token);
|
||||
localStg.set('refreshToken', data.refreshToken);
|
||||
|
||||
const config = { ...axiosConfig };
|
||||
if (config.headers) {
|
||||
config.headers.Authorization = data.token;
|
||||
|
@ -2,7 +2,7 @@ import axios from 'axios';
|
||||
import type { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios';
|
||||
import { REFRESH_TOKEN_CODE } from '@/config';
|
||||
import {
|
||||
getToken,
|
||||
localStg,
|
||||
handleAxiosError,
|
||||
handleBackendError,
|
||||
handleResponseError,
|
||||
@ -49,7 +49,7 @@ export default class CustomAxiosInstance {
|
||||
const contentType = handleConfig.headers['Content-Type'] as string;
|
||||
handleConfig.data = await transformRequestData(handleConfig.data, contentType);
|
||||
// 设置token
|
||||
handleConfig.headers.Authorization = getToken();
|
||||
handleConfig.headers.Authorization = localStg.get('token') || '';
|
||||
}
|
||||
return handleConfig;
|
||||
},
|
||||
|
Reference in New Issue
Block a user