refactor: axios 请求拦截器优化
Former-commit-id: d74d1bed56567aba2a0aafa4497c6c3682be6ef9
This commit is contained in:
@@ -11,14 +11,9 @@ const service = axios.create({
|
||||
// 请求拦截器
|
||||
service.interceptors.request.use(
|
||||
(config: InternalAxiosRequestConfig) => {
|
||||
if (!config.headers) {
|
||||
throw new Error(
|
||||
`Expected 'config' and 'config.headers' not to be undefined`
|
||||
);
|
||||
}
|
||||
const user = useUserStoreHook();
|
||||
if (user.token) {
|
||||
config.headers.Authorization = localStorage.getItem('accessToken');
|
||||
const userStore = useUserStoreHook();
|
||||
if (userStore.token) {
|
||||
config.headers.Authorization = userStore.token;
|
||||
}
|
||||
return config;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user