Files
cozsweet-frontend-nextjs/src/stores/auth/auth-status-checker.tsx
T

28 lines
819 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
/**
* AuthInit 派发器 —— App 启动时读 storage 同步 loginStatus 到状态机
*
* 派发时机:仅 mount 时一次(`useEffect` deps = `[dispatch]`,永远不重跑)。
*
* 与 <OAuthSessionSync /> 平级:
* - AuthStatusChecker: 启动时一次性 init"自己启动时同步"
* - OAuthSessionSync: 持续监听 NextAuth session"别人在写"
*/
import { useEffect } from "react";
import { useAuthDispatch } from "./auth-context";
import { Logger } from "@/utils";
const log = new Logger("StoresAuthAuthStatusChecker");
export function AuthStatusChecker() {
const dispatch = useAuthDispatch();
useEffect(() => {
log.debug("[auth-init] mount → dispatch AuthInit");
dispatch({ type: "AuthInit" });
}, [dispatch]);
// 无 UI
return null;
}