refactor(auth): centralize auth routing via proxy and marker cookie
This commit is contained in:
@@ -79,11 +79,24 @@ async function readGuestId(): Promise<string | undefined> {
|
||||
// ============================================================
|
||||
// Actors(异步服务)
|
||||
// ============================================================
|
||||
/**
|
||||
* 设路由信号 cookie(client 端走 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;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user