chore(auth): add debug logging to guest login flow
Add console.log instrumentation across the guest login pipeline (auth-machine, authRepository, authApi) to trace request lifecycle and surface Zod parsing failures with detailed issue info. Useful for diagnosing lastMessageAt schema mismatches.
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
* 认证相关接口
|
||||
* 原始 Dart: lib/data/services/api/auth_api_client.dart
|
||||
*/
|
||||
import { z } from "zod";
|
||||
|
||||
import { httpClient } from "./http_client";
|
||||
import { ApiPath } from "./api_path";
|
||||
import { ApiEnvelope, unwrap } from "./response_helper";
|
||||
@@ -117,7 +119,29 @@ export class AuthApi {
|
||||
method: "POST",
|
||||
body: body.toJson(),
|
||||
});
|
||||
return GuestLoginResponse.fromJson(unwrap(env) as Record<string, unknown>);
|
||||
console.log("[AuthApi.guestLogin] raw envelope from backend", env);
|
||||
const unwrapped = unwrap(env) as Record<string, unknown>;
|
||||
const userObj = unwrapped.user as { lastMessageAt?: unknown } | undefined;
|
||||
console.log("[AuthApi.guestLogin] unwrapped data (pre-parse)", {
|
||||
hasUser: "user" in unwrapped,
|
||||
userKeys: userObj && typeof userObj === "object" ? Object.keys(userObj) : null,
|
||||
lastMessageAt: userObj?.lastMessageAt,
|
||||
lastMessageAtType: typeof userObj?.lastMessageAt,
|
||||
});
|
||||
try {
|
||||
return GuestLoginResponse.fromJson(unwrapped);
|
||||
} catch (e) {
|
||||
if (e instanceof z.ZodError) {
|
||||
console.error("[AuthApi.guestLogin] ZodError parsing response", {
|
||||
issueCount: e.issues.length,
|
||||
firstIssue: e.issues[0],
|
||||
allPaths: e.issues.map((i) => i.path),
|
||||
});
|
||||
} else {
|
||||
console.error("[AuthApi.guestLogin] unexpected error", e);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user