- {/* Skip 文本按钮 */}
-
+
diff --git a/src/app/splash/components/splash-content.tsx b/src/app/splash/components/splash-content.tsx
index ff5aba04..fdef115d 100644
--- a/src/app/splash/components/splash-content.tsx
+++ b/src/app/splash/components/splash-content.tsx
@@ -10,7 +10,7 @@
*/
import styles from "./splash-content.module.css";
-const APOSTROPHE = "'";
+const APOSTROPHE = "'";
export function SplashContent() {
return (
diff --git a/src/app/splash/components/splash-screen.tsx b/src/app/splash/components/splash-screen.tsx
index 740ba2c2..4f9e61da 100644
--- a/src/app/splash/components/splash-screen.tsx
+++ b/src/app/splash/components/splash-screen.tsx
@@ -1,11 +1,8 @@
"use client";
-import { useRouter } from "next/navigation";
-import { useEffect, useRef } from "react";
-
-import { useAuthState } from "@/contexts/auth/auth-context";
-import { useChatDispatch } from "@/contexts/chat/chat-context";
-import { useUserDispatch } from "@/contexts/user/user-context";
+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";
@@ -17,26 +14,31 @@ import { SplashButton } from "./splash-button";
import styles from "./splash-screen.module.css";
export function SplashScreen() {
- const router = useRouter();
- const { isAuthed } = useAuthGate();
+ // useAuthGate 仍消费(仅读取 isAuthed 用于子组件 gating,不触发跳转)
+ useAuthGate();
+ // 以下 state/dispatch 当前未在本组件消费;保留以便未来按状态驱动的跳转
+ // 重新启用时再解注释 useEffect 即可。
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
const state = useAuthState();
- const wasSuccess = useRef(false);
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
const chatDispatch = useChatDispatch();
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
const userDispatch = useUserDispatch();
- useEffect(() => {
- if (isAuthed) router.replace(ROUTES.chat);
- }, [isAuthed, router]);
+ // 已登录时跳 /chat(已注释:改由 SplashButton 的 Link + 路由守卫统一处理)
+ // useEffect(() => {
+ // if (isAuthed) router.replace(ROUTES.chat);
+ // }, [isAuthed, router]);
- // 登录成功跳 /chat
- useEffect(() => {
- if (state.isSuccess && !wasSuccess.current) {
- wasSuccess.current = true;
- chatDispatch({ type: "ChatAuthStatusChanged" });
- userDispatch({ type: "UserInit" });
- router.replace(ROUTES.chat);
- }
- }, [state.isSuccess, chatDispatch, userDispatch, 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 (
@@ -50,7 +52,7 @@ export function SplashScreen() {
router.push(ROUTES.chat)}
+ skipHref={ROUTES.chat}
onFacebookLogin={() => {
/* Facebook 登录触发由 SplashButton 内部 dispatch */
}}
diff --git a/src/providers/root-providers.tsx b/src/providers/root-providers.tsx
index 971b7450..0df79b9d 100644
--- a/src/providers/root-providers.tsx
+++ b/src/providers/root-providers.tsx
@@ -12,10 +12,10 @@
import type { ReactNode } from "react";
-import { AuthProvider } from "@/contexts/auth/auth-context";
-import { ChatProvider } from "@/contexts/chat/chat-context";
-import { SidebarProvider } from "@/contexts/sidebar/sidebar-context";
-import { UserProvider } from "@/contexts/user/user-context";
+import { AuthProvider } from "@/stores/auth/auth-context";
+import { ChatProvider } from "@/stores/chat/chat-context";
+import { SidebarProvider } from "@/stores/sidebar/sidebar-context";
+import { UserProvider } from "@/stores/user/user-context";
export interface RootProvidersProps {
children: ReactNode;
diff --git a/src/contexts/auth/auth-context.tsx b/src/stores/auth/auth-context.tsx
similarity index 100%
rename from src/contexts/auth/auth-context.tsx
rename to src/stores/auth/auth-context.tsx
diff --git a/src/contexts/auth/auth-machine.ts b/src/stores/auth/auth-machine.ts
similarity index 100%
rename from src/contexts/auth/auth-machine.ts
rename to src/stores/auth/auth-machine.ts
diff --git a/src/contexts/auth/auth-types.ts b/src/stores/auth/auth-types.ts
similarity index 100%
rename from src/contexts/auth/auth-types.ts
rename to src/stores/auth/auth-types.ts
diff --git a/src/contexts/auth/index.ts b/src/stores/auth/index.ts
similarity index 100%
rename from src/contexts/auth/index.ts
rename to src/stores/auth/index.ts
diff --git a/src/contexts/chat/chat-context.tsx b/src/stores/chat/chat-context.tsx
similarity index 100%
rename from src/contexts/chat/chat-context.tsx
rename to src/stores/chat/chat-context.tsx
diff --git a/src/contexts/chat/chat-machine.ts b/src/stores/chat/chat-machine.ts
similarity index 100%
rename from src/contexts/chat/chat-machine.ts
rename to src/stores/chat/chat-machine.ts
diff --git a/src/contexts/chat/chat-types.ts b/src/stores/chat/chat-types.ts
similarity index 100%
rename from src/contexts/chat/chat-types.ts
rename to src/stores/chat/chat-types.ts
diff --git a/src/contexts/chat/index.ts b/src/stores/chat/index.ts
similarity index 100%
rename from src/contexts/chat/index.ts
rename to src/stores/chat/index.ts
diff --git a/src/contexts/sidebar/index.ts b/src/stores/sidebar/index.ts
similarity index 100%
rename from src/contexts/sidebar/index.ts
rename to src/stores/sidebar/index.ts
diff --git a/src/contexts/sidebar/sidebar-context.tsx b/src/stores/sidebar/sidebar-context.tsx
similarity index 100%
rename from src/contexts/sidebar/sidebar-context.tsx
rename to src/stores/sidebar/sidebar-context.tsx
diff --git a/src/contexts/sidebar/sidebar-machine.ts b/src/stores/sidebar/sidebar-machine.ts
similarity index 100%
rename from src/contexts/sidebar/sidebar-machine.ts
rename to src/stores/sidebar/sidebar-machine.ts
diff --git a/src/contexts/sidebar/sidebar-types.ts b/src/stores/sidebar/sidebar-types.ts
similarity index 100%
rename from src/contexts/sidebar/sidebar-types.ts
rename to src/stores/sidebar/sidebar-types.ts
diff --git a/src/contexts/user/index.ts b/src/stores/user/index.ts
similarity index 100%
rename from src/contexts/user/index.ts
rename to src/stores/user/index.ts
diff --git a/src/contexts/user/user-context.tsx b/src/stores/user/user-context.tsx
similarity index 100%
rename from src/contexts/user/user-context.tsx
rename to src/stores/user/user-context.tsx
diff --git a/src/contexts/user/user-machine.ts b/src/stores/user/user-machine.ts
similarity index 100%
rename from src/contexts/user/user-machine.ts
rename to src/stores/user/user-machine.ts
diff --git a/src/contexts/user/user-types.ts b/src/stores/user/user-types.ts
similarity index 100%
rename from src/contexts/user/user-types.ts
rename to src/stores/user/user-types.ts
diff --git a/src/utils/storage.ts b/src/utils/storage.ts
index d98fadc8..280910bc 100644
--- a/src/utils/storage.ts
+++ b/src/utils/storage.ts
@@ -11,15 +11,27 @@
*/
import { createStorage, type Storage } from "unstorage";
import localStorageDriver from "unstorage/drivers/localstorage";
+import memoryDriver from "unstorage/drivers/memory";
import type { ZodType } from "zod";
import { Result, type Result as ResultT } from "@/utils/result";
export class SpAsyncUtil {
// ===== 私有静态状态 =====
- private static _storage: Storage = createStorage({
- driver: localStorageDriver({ base: "cozsweet:" }),
- });
+ // 环境判断 + lazy 初始化:SSR 用 memory driver,浏览器用 localStorage driver。
+ // unstorage 1.10+ 要求显式传入 localStorage,故这里同步注入 window.localStorage。
+ private static _storage: Storage = (() => {
+ if (typeof window === "undefined") {
+ // SSR 环境:无 window,降级为内存驱动
+ return createStorage({ driver: memoryDriver() });
+ }
+ // 浏览器环境:使用 localStorage 驱动
+ return createStorage({
+ driver: localStorageDriver({
+ base: "cozsweet:",
+ }),
+ });
+ })();
// 私有构造函数:禁止实例化(对齐 Dart `SpAsyncUtil._()`)
private constructor() {}