fix(chat): hydrate user avatar after auth restore
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"use client";
|
||||
|
||||
/**
|
||||
* Auth → User 启动同步器
|
||||
*
|
||||
* AuthStatusChecker 只负责恢复 loginStatus;头像等登录用户资料由
|
||||
* UserStorage 持久化在 user machine 这一侧。冷启动直达 /chat 时,
|
||||
* 没有经过 splash/auth 的跳转副作用,因此需要在登录态恢复后主动
|
||||
* hydrate user store。
|
||||
*/
|
||||
import { useEffect, useRef } from "react";
|
||||
|
||||
import { useAuthState } from "@/stores/auth/auth-context";
|
||||
|
||||
import { useUserDispatch } from "./user-context";
|
||||
|
||||
export function UserAuthSync() {
|
||||
const { loginStatus } = useAuthState();
|
||||
const userDispatch = useUserDispatch();
|
||||
const lastInitializedStatusRef = useRef<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (loginStatus === "notLoggedIn" || loginStatus === "guest") {
|
||||
lastInitializedStatusRef.current = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (lastInitializedStatusRef.current === loginStatus) return;
|
||||
lastInitializedStatusRef.current = loginStatus;
|
||||
userDispatch({ type: "UserInit" });
|
||||
}, [loginStatus, userDispatch]);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user