refactor(auth): rename loginType to loginStatus and update related logic

This commit is contained in:
2026-06-11 12:04:48 +08:00
parent 72941d9c9f
commit b50191ed50
7 changed files with 41 additions and 30 deletions
+7 -7
View File
@@ -11,7 +11,7 @@ import { setup, fromPromise, assign } from "xstate";
import { signIn } from "next-auth/react";
import type { AuthProvider } from "@/lib/auth/auth_platform";
import type { LoginType } from "@/models/auth/login-type";
import type { LoginStatus } from "@/models/auth/login-status";
import { authRepository } from "@/data/repositories/auth_repository";
import { AuthStorage } from "@/data/storage/auth/auth_storage";
import { Result } from "@/utils/result";
@@ -42,17 +42,17 @@ async function readGuestId(): Promise<string | undefined> {
// 本轮起不再调 /api/auth/marker 写 cookie(统一迁到 NextAuth session
// cookie 检测,邮箱登录 proxy 行为在后续轮恢复)。
const emailLoginActor = fromPromise<LoginType, { email: string; password: string }>(
const emailLoginActor = fromPromise<LoginStatus, { email: string; password: string }>(
async ({ input }) => {
const guestId = await readGuestId();
const result = await authRepository.emailLogin({ ...input, guestId });
if (Result.isErr(result)) throw result.error;
return "email" as LoginType;
return "email" as LoginStatus;
},
);
const emailRegisterThenLoginActor = fromPromise<
LoginType,
LoginStatus,
{ email: string; password: string; username: string; confirmPassword: string }
>(async ({ input }) => {
const guestId = await readGuestId();
@@ -67,7 +67,7 @@ const emailRegisterThenLoginActor = fromPromise<
guestId,
});
if (Result.isErr(loginResult)) throw loginResult.error;
return "email" as LoginType;
return "email" as LoginStatus;
});
// OAuth 登录 actor:调 next-auth/react 的 signIn(provider) 触发 OAuth 跳转。
@@ -144,7 +144,7 @@ export const authMachine = setup({
onDone: {
target: "success",
actions: assign({
loginType: ({ event }) => event.output,
loginStatus: ({ event }) => event.output,
errorMessage: null,
}),
},
@@ -174,7 +174,7 @@ export const authMachine = setup({
onDone: {
target: "success",
actions: assign({
loginType: ({ event }) => event.output,
loginStatus: ({ event }) => event.output,
errorMessage: null,
}),
},