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
@@ -18,7 +18,7 @@
width: 100%; width: 100%;
min-height: 40px; min-height: 40px;
max-height: 120px; /* 约 5 行 × 24px line-height */ max-height: 120px; /* 约 5 行 × 24px line-height */
padding: 0; padding: 6px 0 0 0; /* 上 6px:让文字视觉下移,避开正中位置 */
border: 0; border: 0;
outline: none; outline: none;
background: transparent; background: transparent;
@@ -28,8 +28,6 @@
line-height: 24px; line-height: 24px;
resize: none; resize: none;
font-family: inherit; font-family: inherit;
display: flex; /* 让 textarea 成为 flex 容器,让文字竖直居中 */
align-items: center; /* 沿 cross axis 居中 = 文字竖直居中于 40px 高度内 */
} }
.textField::placeholder { .textField::placeholder {
+1 -1
View File
@@ -4,4 +4,4 @@
export * from "./auth-mode"; export * from "./auth-mode";
export * from "./auth-panel-mode"; export * from "./auth-panel-mode";
export * from "./login-type"; export * from "./login-status";
+26
View File
@@ -0,0 +1,26 @@
/**
* 登录状态枚举
*
* 原始 Dart: lib/ui/auth/bloc/auth_state.dart 的 `LoginType` 枚举(v7.0 新增)。
*
* 2025-XX 改造:语义从"登录方式"扩展为"当前登录状态"——
* 包含 notLoggedIn / guest / 各 OAuth provider 登录后态。
*
* 字段命名(state)从 `loginType` 改为 `loginStatus`,更贴合语义。
*/
export const LoginStatus = {
/** 未登录(默认初值) */
NotLoggedIn: "notLoggedIn",
/** 游客登录(无需账号,10 轮免费消息) */
Guest: "guest",
/** Facebook OAuth 登录 */
Facebook: "facebook",
/** Google OAuth 登录 */
Google: "google",
/** 邮箱 + 密码登录 */
Email: "email",
/** Apple ID 登录 */
Apple: "apple",
} as const;
export type LoginStatus = (typeof LoginStatus)[keyof typeof LoginStatus];
-14
View File
@@ -1,14 +0,0 @@
/**
* 登录方式枚举
*
* 原始 Dart: lib/ui/auth/bloc/auth_state.dart 的 `LoginType` 枚举(v7.0 新增)。
*/
export const LoginType = {
None: "none",
Facebook: "facebook",
Google: "google",
Email: "email",
Apple: "apple",
} as const;
export type LoginType = (typeof LoginType)[keyof typeof LoginType];
+2 -2
View File
@@ -33,7 +33,7 @@ interface AuthState {
isLoading: boolean; isLoading: boolean;
errorMessage: string | null; errorMessage: string | null;
isSuccess: boolean; isSuccess: boolean;
loginType: MachineContext["loginType"]; loginStatus: MachineContext["loginStatus"];
} }
const AuthStateCtx = createContext<AuthState | null>(null); const AuthStateCtx = createContext<AuthState | null>(null);
@@ -62,7 +62,7 @@ export function AuthProvider({ children }: AuthProviderProps) {
state.matches("loadingOAuth"), state.matches("loadingOAuth"),
errorMessage: state.context.errorMessage, errorMessage: state.context.errorMessage,
isSuccess: state.matches("success"), isSuccess: state.matches("success"),
loginType: state.context.loginType, loginStatus: state.context.loginStatus,
}), }),
[state], [state],
); );
+7 -7
View File
@@ -11,7 +11,7 @@ import { setup, fromPromise, assign } from "xstate";
import { signIn } from "next-auth/react"; import { signIn } from "next-auth/react";
import type { AuthProvider } from "@/lib/auth/auth_platform"; 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 { authRepository } from "@/data/repositories/auth_repository";
import { AuthStorage } from "@/data/storage/auth/auth_storage"; import { AuthStorage } from "@/data/storage/auth/auth_storage";
import { Result } from "@/utils/result"; import { Result } from "@/utils/result";
@@ -42,17 +42,17 @@ async function readGuestId(): Promise<string | undefined> {
// 本轮起不再调 /api/auth/marker 写 cookie(统一迁到 NextAuth session // 本轮起不再调 /api/auth/marker 写 cookie(统一迁到 NextAuth session
// cookie 检测,邮箱登录 proxy 行为在后续轮恢复)。 // cookie 检测,邮箱登录 proxy 行为在后续轮恢复)。
const emailLoginActor = fromPromise<LoginType, { email: string; password: string }>( const emailLoginActor = fromPromise<LoginStatus, { email: string; password: string }>(
async ({ input }) => { async ({ input }) => {
const guestId = await readGuestId(); const guestId = await readGuestId();
const result = await authRepository.emailLogin({ ...input, guestId }); const result = await authRepository.emailLogin({ ...input, guestId });
if (Result.isErr(result)) throw result.error; if (Result.isErr(result)) throw result.error;
return "email" as LoginType; return "email" as LoginStatus;
}, },
); );
const emailRegisterThenLoginActor = fromPromise< const emailRegisterThenLoginActor = fromPromise<
LoginType, LoginStatus,
{ email: string; password: string; username: string; confirmPassword: string } { email: string; password: string; username: string; confirmPassword: string }
>(async ({ input }) => { >(async ({ input }) => {
const guestId = await readGuestId(); const guestId = await readGuestId();
@@ -67,7 +67,7 @@ const emailRegisterThenLoginActor = fromPromise<
guestId, guestId,
}); });
if (Result.isErr(loginResult)) throw loginResult.error; if (Result.isErr(loginResult)) throw loginResult.error;
return "email" as LoginType; return "email" as LoginStatus;
}); });
// OAuth 登录 actor:调 next-auth/react 的 signIn(provider) 触发 OAuth 跳转。 // OAuth 登录 actor:调 next-auth/react 的 signIn(provider) 触发 OAuth 跳转。
@@ -144,7 +144,7 @@ export const authMachine = setup({
onDone: { onDone: {
target: "success", target: "success",
actions: assign({ actions: assign({
loginType: ({ event }) => event.output, loginStatus: ({ event }) => event.output,
errorMessage: null, errorMessage: null,
}), }),
}, },
@@ -174,7 +174,7 @@ export const authMachine = setup({
onDone: { onDone: {
target: "success", target: "success",
actions: assign({ actions: assign({
loginType: ({ event }) => event.output, loginStatus: ({ event }) => event.output,
errorMessage: null, errorMessage: null,
}), }),
}, },
+4 -3
View File
@@ -3,7 +3,7 @@
*/ */
import type { AuthMode } from "@/models/auth/auth-mode"; import type { AuthMode } from "@/models/auth/auth-mode";
import type { AuthPanelMode } from "@/models/auth/auth-panel-mode"; import type { AuthPanelMode } from "@/models/auth/auth-panel-mode";
import type { LoginType } from "@/models/auth/login-type"; import type { LoginStatus } from "@/models/auth/login-status";
export interface AuthState { export interface AuthState {
/** 当前面板模式(Facebook / Email */ /** 当前面板模式(Facebook / Email */
@@ -15,7 +15,8 @@ export interface AuthState {
username: string; username: string;
confirmPassword: string; confirmPassword: string;
errorMessage: string | null; errorMessage: string | null;
loginType: LoginType; /** 当前登录状态(未登录 / 游客 / OAuth / 邮箱) */
loginStatus: LoginStatus;
} }
export const initialState: AuthState = { export const initialState: AuthState = {
@@ -26,5 +27,5 @@ export const initialState: AuthState = {
username: "", username: "",
confirmPassword: "", confirmPassword: "",
errorMessage: null, errorMessage: null,
loginType: "none", loginStatus: "notLoggedIn",
}; };