将mobile 的localstorage key 前缀统一加上了 mobile_

This commit is contained in:
yourname
2025-05-08 13:31:17 +00:00
parent d97690dda9
commit 1b4d1d7fa5

View File

@@ -48,7 +48,7 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
const currentUser = await AuthAPI.getCurrentUser();
setUser(currentUser);
setIsAuthenticated(true);
setLocalStorageWithExpiry('user', currentUser, 24);
setLocalStorageWithExpiry('mobile_user', currentUser, 24);
return { isValid: true, user: currentUser };
} catch (error) {
// 如果API调用失败自动登出
@@ -71,8 +71,8 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
// 保存到状态和本地存储
setToken(token);
setUser(user);
setLocalStorageWithExpiry('token', token, 24); // 24小时过期
setLocalStorageWithExpiry('user', user, 24);
setLocalStorageWithExpiry('mobile_token', token, 24); // 24小时过期
setLocalStorageWithExpiry('mobile_user', user, 24);
// 设置请求头
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
@@ -94,8 +94,8 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children
// 无论API调用成功与否都清除本地状态
setToken(null);
setUser(null);
localStorage.removeItem('token');
localStorage.removeItem('user');
localStorage.removeItem('mobile_token');
localStorage.removeItem('mobile_user');
// 清除请求头
delete axios.defaults.headers.common['Authorization'];
// 清除所有查询缓存