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