From 5bbc445bfef3ea1d88f08fa3ae4cc249de87793e Mon Sep 17 00:00:00 2001 From: Developer Date: Thu, 26 Mar 2026 00:58:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20login()=20=E6=94=B9=E4=B8=BA=E5=BB=B6?= =?UTF-8?q?=E8=BF=9F=E5=90=8E=E5=8F=B0=E6=8B=89=E5=8F=96=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=20getFollowedLiveRooms=20=E5=B9=B6?= =?UTF-8?q?=E5=8F=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit login() 内 await getUserInfo() 导致 login() 慢返回,Zustand set 触发 FollowedLiveStrip 立即发起 getFollowedLiveRooms,与内部 getUserInfo 并发打到 B站新 session,触发风控返回空数据。 改为 setTimeout 1s 后台执行,login() 快速返回,各请求错开发出。 --- store/authStore.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/store/authStore.ts b/store/authStore.ts index 1ee4e95..5fa5769 100644 --- a/store/authStore.ts +++ b/store/authStore.ts @@ -27,16 +27,17 @@ export const useAuthStore = create((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 () => {