fix: login() 改为延迟后台拉取头像,修复 getFollowedLiveRooms 并发问题

login() 内 await getUserInfo() 导致 login() 慢返回,Zustand set 触发
FollowedLiveStrip 立即发起 getFollowedLiveRooms,与内部 getUserInfo
并发打到 B站新 session,触发风控返回空数据。

改为 setTimeout 1s 后台执行,login() 快速返回,各请求错开发出。
This commit is contained in:
Developer
2026-03-26 00:58:39 +08:00
parent 1e0931b5d1
commit 5bbc445bfe

View File

@@ -27,16 +27,17 @@ export const useAuthStore = create<AuthState>((set) => ({
// Migrate: remove SESSDATA from AsyncStorage if it was there before // Migrate: remove SESSDATA from AsyncStorage if it was there before
await AsyncStorage.removeItem('SESSDATA').catch(() => {}); await AsyncStorage.removeItem('SESSDATA').catch(() => {});
set({ sessdata, uid: uid || null, username: username || null, isLoggedIn: true }); set({ sessdata, uid: uid || null, username: username || null, isLoggedIn: true });
// 登录后立即拉取用户信息,确保当前 session 头像可用(不依赖调用方 setProfile // 延迟 1s 后台拉取头像,避免与登录后立即触发的其他请求(如 getFollowedLiveRooms并发
try { setTimeout(() => {
const info = await getUserInfo(); getUserInfo().then(async (info) => {
await AsyncStorage.multiSet([ await AsyncStorage.multiSet([
['UID', String(info.mid)], ['UID', String(info.mid)],
['USERNAME', info.uname], ['USERNAME', info.uname],
['FACE', info.face], ['FACE', info.face],
]); ]).catch(() => {});
set({ face: info.face, username: info.uname, uid: String(info.mid) }); set({ face: info.face, username: info.uname, uid: String(info.mid) });
} catch {} }).catch(() => {});
}, 1000);
}, },
logout: async () => { logout: async () => {