mirror of
https://gh-proxy.org/https://github.com/tiajinsha/JKVideo
synced 2026-07-07 23:18:38 +08:00
fix: login() 改为延迟后台拉取头像,修复 getFollowedLiveRooms 并发问题
login() 内 await getUserInfo() 导致 login() 慢返回,Zustand set 触发 FollowedLiveStrip 立即发起 getFollowedLiveRooms,与内部 getUserInfo 并发打到 B站新 session,触发风控返回空数据。 改为 setTimeout 1s 后台执行,login() 快速返回,各请求错开发出。
This commit is contained in:
@@ -27,16 +27,17 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
// Migrate: remove SESSDATA from AsyncStorage if it was there before
|
||||
await AsyncStorage.removeItem('SESSDATA').catch(() => {});
|
||||
set({ sessdata, uid: uid || null, username: username || null, isLoggedIn: true });
|
||||
// 登录后立即拉取用户信息,确保当前 session 头像可用(不依赖调用方 setProfile)
|
||||
try {
|
||||
const info = await getUserInfo();
|
||||
await AsyncStorage.multiSet([
|
||||
['UID', String(info.mid)],
|
||||
['USERNAME', info.uname],
|
||||
['FACE', info.face],
|
||||
]);
|
||||
set({ face: info.face, username: info.uname, uid: String(info.mid) });
|
||||
} catch {}
|
||||
// 延迟 1s 后台拉取头像,避免与登录后立即触发的其他请求(如 getFollowedLiveRooms)并发
|
||||
setTimeout(() => {
|
||||
getUserInfo().then(async (info) => {
|
||||
await AsyncStorage.multiSet([
|
||||
['UID', String(info.mid)],
|
||||
['USERNAME', info.uname],
|
||||
['FACE', info.face],
|
||||
]).catch(() => {});
|
||||
set({ face: info.face, username: info.uname, uid: String(info.mid) });
|
||||
}).catch(() => {});
|
||||
}, 1000);
|
||||
},
|
||||
|
||||
logout: async () => {
|
||||
|
||||
Reference in New Issue
Block a user