refactor(auth): centralize auth routing via proxy and marker cookie

This commit is contained in:
2026-06-10 12:47:47 +08:00
parent 1db3e3ae31
commit 2066934094
7 changed files with 156 additions and 38 deletions
+14
View File
@@ -79,11 +79,24 @@ async function readGuestId(): Promise<string | undefined> {
// ============================================================
// Actors(异步服务)
// ============================================================
/**
* 设路由信号 cookieclient 端走 marker API)。
* fail-soft:失败仅 warn,不阻断登录主流程(业务 token 已落 localStorage)。
*/
async function setAuthCookieClientSide(): Promise<void> {
try {
await fetch("/api/auth/marker", { method: "POST" });
} catch (e) {
console.warn("[auth-machine] failed to set auth cookie", e);
}
}
const emailLoginActor = fromPromise<LoginType, { email: string; password: string }>(
async ({ input }) => {
const guestId = await readGuestId();
const result = await authRepository.emailLogin({ ...input, guestId });
if (Result.isErr(result)) throw result.error;
await setAuthCookieClientSide();
return "email" as LoginType;
},
);
@@ -104,6 +117,7 @@ const emailRegisterThenLoginActor = fromPromise<
guestId,
});
if (Result.isErr(loginResult)) throw loginResult.error;
await setAuthCookieClientSide();
return "email" as LoginType;
});