b67beaeae6
AuthReset was declared in the AuthEvent union and handled in auth-machine.idle.on with `assign(() => initialState)`, but nothing in the codebase actually dispatches it anymore. History of dispatch sites (now all gone): - sidebar-screen.tsx previously dispatched AuthReset post-logout alongside router.replace(ROUTES.chat) — that was simplified to just dispatch AuthLogoutSubmitted, the state machine's loggingOut state now does the context reset itself in onDone via the same `assign(() => initialState)` action. - chat-screen / splash / auth screens never dispatched it. - The /auth screen's pendingRedirect-based redirect loop doesn't need it (the redirect is one-shot, not a state that needs resetting). So the event handler is unreachable. Remove the type member from auth-events.ts and the handler from auth-machine.ts. No behavior change: the only path that 'reset auth state' was already covered by loggingOut.onDone. Verified via `grep -rn 'AuthReset' src/`: only 2 hits remain after this commit — both are the type declaration and the machine handler, which is now also gone (zero hits).
42 lines
2.0 KiB
TypeScript
42 lines
2.0 KiB
TypeScript
/**
|
|
* Auth 状态机:事件联合
|
|
*
|
|
* 事件名与原 Dart AuthEvent 对齐。
|
|
*/
|
|
import type { AuthProvider } from "@/lib/auth/auth_platform";
|
|
import type { AuthMode } from "@/models/auth/auth-mode";
|
|
import type { AuthPanelMode } from "@/models/auth/auth-panel-mode";
|
|
|
|
export type AuthEvent =
|
|
// 内部 UI 事件
|
|
| { type: "AuthPanelModeChanged"; mode: AuthPanelMode }
|
|
| { type: "AuthModeChanged"; mode: AuthMode }
|
|
| { type: "AuthFormCleared" }
|
|
| { type: "AuthLogoutSubmitted" }
|
|
/** App 启动时一次性派发 —— 读 storage 把 loginStatus 同步到状态机 */
|
|
| { type: "AuthInit" }
|
|
/** 显式游客登录 —— splash 上点"游客模式"按钮触发(不自动) */
|
|
| { type: "AuthGuestLoginSubmitted" }
|
|
// 业务事件(提交)
|
|
| { type: "AuthEmailLoginSubmitted"; email: string; password: string }
|
|
| {
|
|
type: "AuthEmailRegisterSubmitted";
|
|
email: string;
|
|
password: string;
|
|
username: string;
|
|
confirmPassword: string;
|
|
}
|
|
// 社交登录 —— 状态机内部调 next-auth/react 的 signIn(provider)
|
|
| { type: "AuthGoogleLoginSubmitted"; provider: AuthProvider }
|
|
| { type: "AuthFacebookLoginSubmitted"; provider: AuthProvider }
|
|
| { type: "AuthAppleLoginSubmitted" }
|
|
// OAuth 回调后:把 OAuth provider token 转交后端换业务 token
|
|
// 由 <OAuthSessionSync /> 监听 useSession() 派发
|
|
| { type: "AuthGoogleSyncSubmitted"; idToken: string }
|
|
| { type: "AuthFacebookSyncSubmitted"; accessToken: string }
|
|
// ──────────────────────────────────────────────────────────────────────
|
|
// splash / auth screen 跳完 /chat 后清"刚按了"信号(一次性):
|
|
// `pendingRedirect` 在 login onDone action 里自动置 true(不是按钮派的)
|
|
// —— 因此只需要 `AuthClearPendingRedirect` 一个事件
|
|
| { type: "AuthClearPendingRedirect" };
|