fix: 登录后头像不更新 — 将 getUserInfo 合并进 login()

登录流程之前分两步:login() 只设 isLoggedIn,getUserInfo/setProfile
由 LoginModal 调用。网络抖动或 B站 session 传播延迟时 getUserInfo
抛错被静默吞掉,face 不更新,直到下次启动 restore() 才修复。

修复:login() 内部完成 getUserInfo + 持久化,LoginModal 只需
await login() 后关闭弹窗,不再重复获取头像。
This commit is contained in:
Developer
2026-03-26 00:49:46 +08:00
parent 463c0db058
commit 1e0931b5d1
2 changed files with 14 additions and 12 deletions

View File

@@ -14,7 +14,7 @@ import * as FileSystem from "expo-file-system/legacy";
import * as MediaLibrary from "expo-media-library";
import QRCode from "react-native-qrcode-svg";
import { Ionicons } from "@expo/vector-icons";
import { generateQRCode, pollQRCode, getUserInfo } from "../services/bilibili";
import { generateQRCode, pollQRCode } from "../services/bilibili";
import { useAuthStore } from "../store/authStore";
import { useTheme } from "../utils/theme";
@@ -33,7 +33,6 @@ export function LoginModal({ visible, onClose }: Props) {
>("loading");
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
const login = useAuthStore((s) => s.login);
const setProfile = useAuthStore((s) => s.setProfile);
const theme = useTheme();
// sheet 滑入动画
@@ -86,14 +85,11 @@ export function LoginModal({ visible, onClose }: Props) {
clearInterval(pollRef.current!);
try {
await login(result.cookie, "", "");
if (cancelled) return;
setStatus("done");
const info = await getUserInfo();
if (!cancelled) setProfile(info.face, info.uname, String(info.mid));
} catch {
if (!cancelled) setStatus("error");
return;
}
onClose();
if (!cancelled) onClose();
}
} catch {
// Network error during poll — ignore, will retry next interval