fix(auth): stop parsing logout response body (avoids ZodError on null data)
Root cause: backend `/auth/logout` returns `{ success: true, data: null }`
(no business payload for a fire-and-forget endpoint). The previous
`AuthApi.logout` ran `unwrap(env)` (which passes null through, since
null is defined) and then `LogoutResponse.fromJson(null)`, which
Zod-parses as `z.object(...)` and throws "Invalid input: expected
object, received null".
The error was caught in `AuthRepository.logout` with
`console.warn(... clearing local anyway)` — logout actually still
worked (local clear ran), but a noisy red ZodError hit the console on
every logout click.
Fix: align `AuthApi.logout` with the existing fire-and-forget pattern
used by `register` and `sendCode` — call `httpClient` and ignore the
response body. Drop the now-unused `LogoutResponse` import.
`AuthRepository.logout` already discards the return value, so the
`Promise<LogoutResponse> → Promise<void>` signature change is safe.
Bundled in this commit (unrelated):
- chat-machine.actors.ts / user-machine.ts: removed stale design-doc
comment blocks (IDE/linter cleanup)
- user-machine.actors.ts: removed redundant `userStorage.clearUserData()`
from `userLogoutActor` — `authRepo.logout` already clears local
user data, so this was a no-op duplicate.
- sidebar-screen.tsx: removed one stale comment line.
This commit is contained in:
@@ -1,18 +1,5 @@
|
||||
/**
|
||||
* Chat 状态机:4 个 XState actor
|
||||
*
|
||||
* 从 `chat-machine.ts` 抽出的"Actors"段:
|
||||
* - `loadQuotaActor`(fromPromise,仅游客有意义 —— 拉日配 + 总配)
|
||||
* - `loadHistoryActor`(fromPromise —— local → network → save network to local 3 步)
|
||||
* - `sendMessageHttpActor`(fromPromise,已 wire —— "一次发送 = 一次返回")
|
||||
* - `loadMoreHistoryActor`(fromPromise —— 翻页,不走 local-first)
|
||||
* - `chatWebSocketActor`(fromCallback,长生命周期 —— 仅 userSession 期间 invoke)
|
||||
*
|
||||
* 设计:
|
||||
* - 依赖 `chat-machine.helpers.ts`(纯函数 + 数据加载)
|
||||
* - 依赖 `createChatWebSocket`(`@/core/net/chat-websocket`)
|
||||
* - 保留全链日志(用户要求"不要将其删除")
|
||||
* - 命名约定:`[chat-machine]` 前缀 —— 与 `chat-machine.ts` 的日志对齐
|
||||
*/
|
||||
|
||||
import { fromPromise, fromCallback } from "xstate";
|
||||
|
||||
@@ -70,5 +70,4 @@ export const userFetchActor = fromPromise<UserView | null>(async () => {
|
||||
*/
|
||||
export const userLogoutActor = fromPromise<void>(async () => {
|
||||
await authRepo.logout();
|
||||
await userStorage.clearUserData();
|
||||
});
|
||||
@@ -1,19 +1,5 @@
|
||||
/**
|
||||
* User 状态机(XState v5)
|
||||
*
|
||||
* 原始 Dart: lib/ui/user/bloc/user bloc + user state + user event
|
||||
*
|
||||
* 设计要点:
|
||||
* - XState v5 `setup({...}).createMachine({...})` 声明式 API
|
||||
* - HTTP 操作用 `fromPromise` actor(一次性 Promise)→ 见 `user-machine.actors.ts`
|
||||
* - 纯函数 / 数据加载 → 见 `user-machine.helpers.ts`
|
||||
* - 同步状态更新用 `assign` actions(inline 在 setup() 中)
|
||||
* - 保持事件类型名与原 Dart 一致
|
||||
*
|
||||
* 分层:
|
||||
* - helpers: 无 XState 依赖(DTO 映射 + 数据加载)
|
||||
* - actors: 依赖 helpers(异步 actor 实现)
|
||||
* - machine: 依赖 actors(XState setup + 状态图)
|
||||
*/
|
||||
import { setup, assign } from "xstate";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user