mirror of
https://gh-proxy.org/https://github.com/tiajinsha/JKVideo
synced 2026-07-08 07:28:37 +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:
@@ -14,7 +14,7 @@ import * as FileSystem from "expo-file-system/legacy";
|
|||||||
import * as MediaLibrary from "expo-media-library";
|
import * as MediaLibrary from "expo-media-library";
|
||||||
import QRCode from "react-native-qrcode-svg";
|
import QRCode from "react-native-qrcode-svg";
|
||||||
import { Ionicons } from "@expo/vector-icons";
|
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 { useAuthStore } from "../store/authStore";
|
||||||
import { useTheme } from "../utils/theme";
|
import { useTheme } from "../utils/theme";
|
||||||
|
|
||||||
@@ -33,7 +33,6 @@ export function LoginModal({ visible, onClose }: Props) {
|
|||||||
>("loading");
|
>("loading");
|
||||||
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||||
const login = useAuthStore((s) => s.login);
|
const login = useAuthStore((s) => s.login);
|
||||||
const setProfile = useAuthStore((s) => s.setProfile);
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
// sheet 滑入动画
|
// sheet 滑入动画
|
||||||
@@ -86,14 +85,11 @@ export function LoginModal({ visible, onClose }: Props) {
|
|||||||
clearInterval(pollRef.current!);
|
clearInterval(pollRef.current!);
|
||||||
try {
|
try {
|
||||||
await login(result.cookie, "", "");
|
await login(result.cookie, "", "");
|
||||||
if (cancelled) return;
|
|
||||||
setStatus("done");
|
|
||||||
const info = await getUserInfo();
|
|
||||||
if (!cancelled) setProfile(info.face, info.uname, String(info.mid));
|
|
||||||
} catch {
|
} catch {
|
||||||
if (!cancelled) setStatus("error");
|
if (!cancelled) setStatus("error");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
onClose();
|
if (!cancelled) onClose();
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Network error during poll — ignore, will retry next interval
|
// Network error during poll — ignore, will retry next interval
|
||||||
|
|||||||
@@ -24,13 +24,19 @@ export const useAuthStore = create<AuthState>((set) => ({
|
|||||||
|
|
||||||
login: async (sessdata, uid, username) => {
|
login: async (sessdata, uid, username) => {
|
||||||
await setSecure('SESSDATA', sessdata);
|
await setSecure('SESSDATA', sessdata);
|
||||||
await AsyncStorage.multiSet([
|
|
||||||
['UID', uid],
|
|
||||||
['USERNAME', username ?? ''],
|
|
||||||
]);
|
|
||||||
// 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, 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 () => {
|
logout: async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user