refactor(auth): rename loginType to loginStatus and update related logic
This commit is contained in:
@@ -33,7 +33,7 @@ interface AuthState {
|
||||
isLoading: boolean;
|
||||
errorMessage: string | null;
|
||||
isSuccess: boolean;
|
||||
loginType: MachineContext["loginType"];
|
||||
loginStatus: MachineContext["loginStatus"];
|
||||
}
|
||||
|
||||
const AuthStateCtx = createContext<AuthState | null>(null);
|
||||
@@ -62,7 +62,7 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
state.matches("loadingOAuth"),
|
||||
errorMessage: state.context.errorMessage,
|
||||
isSuccess: state.matches("success"),
|
||||
loginType: state.context.loginType,
|
||||
loginStatus: state.context.loginStatus,
|
||||
}),
|
||||
[state],
|
||||
);
|
||||
|
||||
@@ -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,
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
import type { AuthMode } from "@/models/auth/auth-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 {
|
||||
/** 当前面板模式(Facebook / Email) */
|
||||
@@ -15,7 +15,8 @@ export interface AuthState {
|
||||
username: string;
|
||||
confirmPassword: string;
|
||||
errorMessage: string | null;
|
||||
loginType: LoginType;
|
||||
/** 当前登录状态(未登录 / 游客 / OAuth / 邮箱) */
|
||||
loginStatus: LoginStatus;
|
||||
}
|
||||
|
||||
export const initialState: AuthState = {
|
||||
@@ -26,5 +27,5 @@ export const initialState: AuthState = {
|
||||
username: "",
|
||||
confirmPassword: "",
|
||||
errorMessage: null,
|
||||
loginType: "none",
|
||||
loginStatus: "notLoggedIn",
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user