refactor(auth): centralize login status sync

This commit is contained in:
2026-06-18 12:52:49 +08:00
parent 0d0dabaace
commit f600e11d55
11 changed files with 115 additions and 128 deletions
+2 -11
View File
@@ -9,7 +9,6 @@ import { useRouter } from "next/navigation";
import { MobileShell } from "@/app/_components/core";
import { useAuthDispatch, useAuthState } from "@/stores/auth/auth-context";
import { useUserDispatch } from "@/stores/user/user-context";
import { ROUTES } from "@/router/routes";
import { AuthBackground, AuthPanel } from "./components";
@@ -18,10 +17,9 @@ import styles from "./components/auth-screen.module.css";
export function AuthScreen() {
const state = useAuthState();
const authDispatch = useAuthDispatch();
const userDispatch = useUserDispatch();
const router = useRouter();
// 邮箱登录成功 → 通知 User + 跳转
// 邮箱登录成功 → 跳转User hydrate 由根级 <UserAuthSync /> 监听 loginStatus 变化处理。
// 用 pendingRedirect flag(不是 useRef transition detection)——
// re-mount 时 flag 在 auth context 里持久,区分"刚按了"和"re-visit"准确无误。
useEffect(() => {
@@ -37,16 +35,9 @@ export function AuthScreen() {
"[auth-screen] useEffect → router.replace(/chat) [via pendingRedirect flag]",
);
authDispatch({ type: "AuthClearPendingRedirect" });
userDispatch({ type: "UserInit" });
router.replace(ROUTES.chat);
}
}, [
state.loginStatus,
state.pendingRedirect,
authDispatch,
userDispatch,
router,
]);
}, [state.loginStatus, state.pendingRedirect, authDispatch, router]);
return (
<MobileShell>