refactor(splash): encapsulate auth logic in SplashButton for SSR support

This commit is contained in:
2026-06-09 18:59:34 +08:00
parent a5d8214650
commit 199a14650e
4 changed files with 55 additions and 58 deletions
+10 -38
View File
@@ -1,10 +1,13 @@
"use client";
/**
* Splash 屏幕(纯布局 / Server Component
*
* 鉴权流程逻辑已封装到 `<SplashButton>` 内部(client 组件):
* - 已登录检测 / 登录成功跳转 / Facebook 登录 dispatch
* - 跨 store 初始化(ChatAuthStatusChanged / UserInit
*
* 本组件职责:纯 JSX 布局,无 hooks → 可作为 Server Component 直接 SSR。
*/
import { useAuthState } from "@/stores/auth/auth-context";
import { useChatDispatch } from "@/stores/chat/chat-context";
import { useUserDispatch } from "@/stores/user/user-context";
import { useAuthGate } from "@/lib/auth/use-auth-gate";
import { ROUTES } from "@/lib/routes";
import { MobileShell } from "@/app/_components/core/mobile-shell";
import { SplashBackground } from "./splash-background";
@@ -14,32 +17,6 @@ import { SplashButton } from "./splash-button";
import styles from "./splash-screen.module.css";
export function SplashScreen() {
// useAuthGate 仍消费(仅读取 isAuthed 用于子组件 gating,不触发跳转)
useAuthGate();
// 以下 state/dispatch 当前未在本组件消费;保留以便未来按状态驱动的跳转
// 重新启用时再解注释 useEffect 即可。
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const state = useAuthState();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const chatDispatch = useChatDispatch();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const userDispatch = useUserDispatch();
// 已登录时跳 /chat(已注释:改由 SplashButton 的 Link + 路由守卫统一处理)
// useEffect(() => {
// if (isAuthed) router.replace(ROUTES.chat);
// }, [isAuthed, router]);
// 登录成功跳 /chat(已注释:改由 SplashButton 的 Link + 路由守卫统一处理)
// useEffect(() => {
// if (state.isSuccess && !wasSuccess.current) {
// wasSuccess.current = true;
// chatDispatch({ type: "ChatAuthStatusChanged" });
// userDispatch({ type: "UserInit" });
// router.replace(ROUTES.chat);
// }
// }, [state.isSuccess, chatDispatch, userDispatch, router]);
return (
<MobileShell background="var(--color-sidebar-background)">
<div className={styles.wrapper}>
@@ -51,12 +28,7 @@ export function SplashScreen() {
<div className={styles.spacer} />
<SplashContent />
<div className={styles.buttonArea}>
<SplashButton
skipHref={ROUTES.chat}
onFacebookLogin={() => {
/* Facebook 登录触发由 SplashButton 内部 dispatch */
}}
/>
<SplashButton />
</div>
<p className={styles.bottom}>
Elio Silvestri, Your exclusive AI boyfriend