fix(chat): constrain auth state transitions

This commit is contained in:
2026-06-23 14:10:59 +08:00
parent ebd44c4980
commit 7dd4878d7d
2 changed files with 7 additions and 14 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
* - `ChatGuestLogin`:游客进入 /chat —— 拉本地消息 + 初始化配额(不连 WS) * - `ChatGuestLogin`:游客进入 /chat —— 拉本地消息 + 初始化配额(不连 WS)
* - `ChatNonVipLogin`:非 VIP 用户进入 /chat —— 拉服务器端首屏,不连 WS * - `ChatNonVipLogin`:非 VIP 用户进入 /chat —— 拉服务器端首屏,不连 WS
* - `ChatVipLogin`VIP 用户进入 /chat —— 拉服务器端首屏 + 连 WStoken 在 payload * - `ChatVipLogin`VIP 用户进入 /chat —— 拉服务器端首屏 + 连 WStoken 在 payload
* - `ChatLogout`:登出 / 切换用户 —— 断 WS + 清消息 * - `ChatLogout`正式登录用户登出 —— 断 WS + 清消息
* *
* 设计:所有WS / 历史 / 配额相关副作用全部通过派发事件给 chat 机器处理, * 设计:所有WS / 历史 / 配额相关副作用全部通过派发事件给 chat 机器处理,
* chat-screen 不直接创建 ChatWebSocket / 不读 AuthStorage(除 token 取值)。 * chat-screen 不直接创建 ChatWebSocket / 不读 AuthStorage(除 token 取值)。
+6 -13
View File
@@ -7,7 +7,12 @@
* - `ChatGuestLogin` → 游客会话(断 WS = 不连) * - `ChatGuestLogin` → 游客会话(断 WS = 不连)
* - `ChatNonVipLogin { token }` → 非 VIP 用户会话(不连 WS) * - `ChatNonVipLogin { token }` → 非 VIP 用户会话(不连 WS)
* - `ChatVipLogin { token }` → VIP 用户会话(连 WS * - `ChatVipLogin { token }` → VIP 用户会话(连 WS
* - `ChatLogout` → 登出(机器自动 cleanup WS actor * - `ChatLogout` → 正式登录用户登出(机器自动 cleanup WS actor
*
* 登录态流转约束:
* - 未登录:可以进入游客登录 / 其他登录。
* - 游客登录:只可以升级为其他登录,不响应退出。
* - 其他登录:可以退出,也可以在非 VIP / VIP 间切换,不响应游客登录。
* *
* 状态结构(parent state 模式): * 状态结构(parent state 模式):
* - `idle`:屏没挂 / 登出 * - `idle`:屏没挂 / 登出
@@ -364,10 +369,6 @@ export const chatMachine = setup({
guestSession: { guestSession: {
on: { on: {
ChatLogout: {
target: "#chat.idle",
actions: "clearChatSession",
},
ChatNonVipLogin: { ChatNonVipLogin: {
target: "#chat.nonVipUserSession", target: "#chat.nonVipUserSession",
actions: "startUserSession", actions: "startUserSession",
@@ -468,10 +469,6 @@ export const chatMachine = setup({
target: "#chat.idle", target: "#chat.idle",
actions: "clearChatSession", actions: "clearChatSession",
}, },
ChatGuestLogin: {
target: "#chat.guestSession",
actions: "startGuestSession",
},
ChatNonVipLogin: { ChatNonVipLogin: {
target: "#chat.nonVipUserSession", target: "#chat.nonVipUserSession",
reenter: true, reenter: true,
@@ -595,10 +592,6 @@ export const chatMachine = setup({
target: "#chat.idle", target: "#chat.idle",
actions: "clearChatSession", actions: "clearChatSession",
}, },
ChatGuestLogin: {
target: "#chat.guestSession",
actions: "startGuestSession",
},
ChatNonVipLogin: { ChatNonVipLogin: {
target: "#chat.nonVipUserSession", target: "#chat.nonVipUserSession",
actions: "startUserSession", actions: "startUserSession",