mirror of
https://gh-proxy.org/https://github.com/tiajinsha/JKVideo
synced 2026-07-07 23:18:38 +08:00
fix: 登录后头像不更新 — 将 getUserInfo 合并进 login()
登录流程之前分两步:login() 只设 isLoggedIn,getUserInfo/setProfile 由 LoginModal 调用。网络抖动或 B站 session 传播延迟时 getUserInfo 抛错被静默吞掉,face 不更新,直到下次启动 restore() 才修复。 修复:login() 内部完成 getUserInfo + 持久化,LoginModal 只需 await login() 后关闭弹窗,不再重复获取头像。
This commit is contained in:
@@ -24,13 +24,19 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
|
||||
login: async (sessdata, uid, username) => {
|
||||
await setSecure('SESSDATA', sessdata);
|
||||
await AsyncStorage.multiSet([
|
||||
['UID', uid],
|
||||
['USERNAME', username ?? ''],
|
||||
]);
|
||||
// Migrate: remove SESSDATA from AsyncStorage if it was there before
|
||||
await AsyncStorage.removeItem('SESSDATA').catch(() => {});
|
||||
set({ sessdata, uid, username: username ?? null, isLoggedIn: true });
|
||||
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 {}
|
||||
},
|
||||
|
||||
logout: async () => {
|
||||
|
||||
Reference in New Issue
Block a user