refactor(app): tighten chat and sync boundaries

This commit is contained in:
2026-07-01 14:03:25 +08:00
parent f6e7adbe96
commit 760e4fe343
19 changed files with 215 additions and 677 deletions
-1
View File
@@ -2,7 +2,6 @@
* @file Automatically generated by barrelsby.
*/
export * from "./user-auth-sync";
export * from "./user-context";
export * from "./user-events";
export * from "./user-machine.actors";
-39
View File
@@ -1,39 +0,0 @@
"use client";
/**
* Auth → User 同步器
*
* AuthStatusChecker 只负责恢复 loginStatus;用户资料由 user machine
* 管理。这里持续监听登录态变化:
* - notLoggedIn → 清空本地 user context
* - guest / email / OAuth → 重新 hydrate user store
*/
import { useEffect, useRef } from "react";
import type { LoginStatus } from "@/data/dto/auth";
import { useAuthState } from "@/stores/auth/auth-context";
import { useUserDispatch } from "./user-context";
export function UserAuthSync() {
const { hasInitialized, isLoading, loginStatus } = useAuthState();
const userDispatch = useUserDispatch();
const prevLoginStatusRef = useRef<LoginStatus | null>(null);
useEffect(() => {
if (!hasInitialized || isLoading) return;
const prev = prevLoginStatusRef.current;
if (prev === loginStatus) return;
prevLoginStatusRef.current = loginStatus;
if (loginStatus === "notLoggedIn") {
userDispatch({ type: "UserClearLocal" });
return;
}
userDispatch({ type: "UserInit" });
}, [hasInitialized, isLoading, loginStatus, userDispatch]);
return null;
}