fix:splash 界面重定向界面问题

This commit is contained in:
2026-06-11 16:06:36 +08:00
parent a6bc6941d4
commit e3d549d660
6 changed files with 30 additions and 66 deletions
+2 -9
View File
@@ -15,8 +15,8 @@
*
* 跳转时序:
* 1. 派发事件(如 `AuthGuestLoginSubmitted`
* 2. auth machine 进 loading state → API 调用 → onDone → state.isSuccess = true
* 3. useEffect 监听到 isSuccess → 调 chat/user store 初始化 + router.replace("/chat")
* 2. auth machine 进 loading state → API 调用 → onDone → loginStatus 更新
* 3. useEffect 监听到 isSuccess (= loginStatus !== "notLoggedIn") → 调 chat/user store 初始化 + router.replace("/chat")
*/
import { useRouter } from "next/navigation";
import { useEffect, useRef } from "react";
@@ -47,17 +47,10 @@ export function SplashButton() {
// 邮箱/OAuth/游客登录成功跳 /chat + 通知 chat/user 初始化
useEffect(() => {
// DEBUGisSuccess 状态透明化
console.log("[splash-button] useEffect state.isSuccess", {
isSuccess: state.isSuccess,
wasSuccess: wasSuccess.current,
willRedirect: state.isSuccess && !wasSuccess.current,
});
if (state.isSuccess && !wasSuccess.current) {
wasSuccess.current = true;
chatDispatch({ type: "ChatAuthStatusChanged" });
userDispatch({ type: "UserInit" });
console.log("[splash-button] useEffect → router.replace(/chat) [via isSuccess]");
router.replace(ROUTES.chat);
}
}, [state.isSuccess, chatDispatch, userDispatch, router]);
@@ -22,9 +22,6 @@ export function SplashScreen() {
// - 都没有 → 留在 splash(**不**自动创建游客账号 —— 见 auth-machine.ts 的 checkAuthStatusActor
//
// proxy 读不到 localStorageEdge runtime),所以这条 fallback 必须在 Client 侧。
//
// DEBUGclient 端**不**用 Loggerpino 引入会爆 client bundle),改用 console.log
// 临时调试,bug 修完即删。
useEffect(() => {
let cancelled = false;
void (async () => {
@@ -40,15 +37,7 @@ export function SplashScreen() {
(loginTok != null && loginTok.length > 0) ||
(guestTok != null && guestTok.length > 0);
console.log("[splash] useEffect token check", {
loginToken: loginTok ? `${loginTok.slice(0, 8)}...` : null,
guestToken: guestTok ? `${guestTok.slice(0, 8)}...` : null,
hasAny,
willRedirect: hasAny && !cancelled,
});
if (!cancelled && hasAny) {
console.log("[splash] useEffect → router.replace(/chat)");
router.replace(ROUTES.chat);
}
})();