fix:splash 界面重定向界面问题
This commit is contained in:
@@ -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(() => {
|
||||
// DEBUG:isSuccess 状态透明化
|
||||
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 读不到 localStorage(Edge runtime),所以这条 fallback 必须在 Client 侧。
|
||||
//
|
||||
// DEBUG:client 端**不**用 Logger(pino 引入会爆 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);
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user