优化认证提供者组件,移除不必要的请求拦截器代码,使用useQuery简化登录状态检查,增强用户认证逻辑的清晰性和可维护性。
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user