优化认证提供者组件,移除不必要的请求拦截器代码,使用useQuery简化登录状态检查,增强用户认证逻辑的清晰性和可维护性。

This commit is contained in:
zyh
2025-04-10 05:03:36 +00:00
parent 5d338ca7c5
commit 4a6aa03fff
2 changed files with 43 additions and 27 deletions

View File

@@ -113,17 +113,6 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
// 设置请求拦截器
useEffect(() => {
// console.log('token状态变化当前token:', token);
// if (token) {
// // 从localStorage中恢复token时设置全局请求头
// axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
// console.log('从状态中恢复全局Authorization头:', axios.defaults.headers.common['Authorization']);
// } else {
// // 登出时删除请求头
// delete axios.defaults.headers.common['Authorization'];
// console.log('已删除全局Authorization头');
// }
// 设置响应拦截器处理401错误
const responseInterceptor = axios.interceptors.response.use(
(response) => response,