refactor(auth): remove unused machine state
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
/**
|
||||
* 认证模式(登录 / 注册)
|
||||
*
|
||||
*
|
||||
*/
|
||||
export const AuthMode = {
|
||||
Login: "login",
|
||||
Register: "register",
|
||||
} as const;
|
||||
|
||||
export type AuthMode = (typeof AuthMode)[keyof typeof AuthMode];
|
||||
@@ -2,7 +2,6 @@
|
||||
* @file Automatically generated by barrelsby.
|
||||
*/
|
||||
|
||||
export * from "./auth_mode";
|
||||
export * from "./auth_panel_mode";
|
||||
export * from "./facebook_user_data";
|
||||
export * from "./login_status";
|
||||
|
||||
@@ -58,22 +58,12 @@ function createTestAuthMachine(
|
||||
}
|
||||
|
||||
describe("authMachine", () => {
|
||||
it("updates panel mode, auth mode, and unsupported Apple login errors", () => {
|
||||
it("updates panel mode", () => {
|
||||
const actor = createActor(createTestAuthMachine()).start();
|
||||
|
||||
actor.send({ type: "AuthPanelModeChanged", mode: "email" });
|
||||
actor.send({ type: "AuthModeChanged", mode: "register" });
|
||||
|
||||
expect(actor.getSnapshot().context.authPanelMode).toBe("email");
|
||||
expect(actor.getSnapshot().context.authMode).toBe("register");
|
||||
|
||||
actor.send({ type: "AuthAppleLoginSubmitted" });
|
||||
expect(actor.getSnapshot().context.errorMessage).toBe(
|
||||
"Apple login not implemented",
|
||||
);
|
||||
|
||||
actor.send({ type: "AuthFormCleared" });
|
||||
expect(actor.getSnapshot().context.errorMessage).toBeNull();
|
||||
|
||||
actor.stop();
|
||||
});
|
||||
|
||||
@@ -25,11 +25,6 @@ import type { AuthEvent, AuthState as MachineContext } from "./auth-machine";
|
||||
*/
|
||||
interface AuthState {
|
||||
authPanelMode: MachineContext["authPanelMode"];
|
||||
authMode: MachineContext["authMode"];
|
||||
email: string;
|
||||
password: string;
|
||||
username: string;
|
||||
confirmPassword: string;
|
||||
isLoading: boolean;
|
||||
errorMessage: string | null;
|
||||
/** 当前登录状态(未登录 / 游客 / OAuth / 邮箱) */
|
||||
@@ -52,11 +47,6 @@ export function AuthProvider({ children }: AuthProviderProps) {
|
||||
const authState = useMemo<AuthState>(
|
||||
() => ({
|
||||
authPanelMode: state.context.authPanelMode,
|
||||
authMode: state.context.authMode,
|
||||
email: state.context.email,
|
||||
password: state.context.password,
|
||||
username: state.context.username,
|
||||
confirmPassword: state.context.confirmPassword,
|
||||
// isLoading 覆盖邮箱登录 / 邮箱注册 / OAuth 跳转(NextAuth 重定向期间)/
|
||||
// OAuth 回调后端 sync / 显式游客登录
|
||||
isLoading:
|
||||
|
||||
@@ -4,13 +4,11 @@
|
||||
* 事件名与原 Dart AuthEvent 对齐。
|
||||
*/
|
||||
import type { AuthProvider } from "@/lib/auth/auth_platform";
|
||||
import type { AuthMode, AuthPanelMode } from "@/data/dto/auth";
|
||||
import type { AuthPanelMode } from "@/data/dto/auth";
|
||||
|
||||
export type AuthEvent =
|
||||
// 内部 UI 事件
|
||||
| { type: "AuthPanelModeChanged"; mode: AuthPanelMode }
|
||||
| { type: "AuthModeChanged"; mode: AuthMode }
|
||||
| { type: "AuthFormCleared" }
|
||||
| { type: "AuthLogoutSubmitted" }
|
||||
/** App 启动时一次性派发 —— 读 storage 把 loginStatus 同步到状态机 */
|
||||
| { type: "AuthInit" }
|
||||
@@ -27,7 +25,6 @@ export type AuthEvent =
|
||||
// 社交登录 —— 状态机内部调 next-auth/react 的 signIn(provider)
|
||||
| { type: "AuthGoogleLoginSubmitted"; provider: AuthProvider }
|
||||
| { type: "AuthFacebookLoginSubmitted"; provider: AuthProvider }
|
||||
| { type: "AuthAppleLoginSubmitted" }
|
||||
// OAuth 回调后:把 OAuth provider token 转交后端换业务 token
|
||||
// 由 <OAuthSessionSync /> 监听 useSession() 派发
|
||||
| { type: "AuthGoogleSyncSubmitted"; idToken: string }
|
||||
|
||||
@@ -70,21 +70,6 @@ export const authMachine = setup({
|
||||
errorMessage: null,
|
||||
}),
|
||||
},
|
||||
AuthModeChanged: {
|
||||
actions: assign({
|
||||
authMode: ({ event }) => event.mode,
|
||||
errorMessage: null,
|
||||
}),
|
||||
},
|
||||
AuthFormCleared: {
|
||||
actions: assign({
|
||||
email: "",
|
||||
password: "",
|
||||
username: "",
|
||||
confirmPassword: "",
|
||||
errorMessage: null,
|
||||
}),
|
||||
},
|
||||
AuthLogoutSubmitted: {
|
||||
guard: "canLogoutToGuest",
|
||||
target: "loggingOut",
|
||||
@@ -100,11 +85,6 @@ export const authMachine = setup({
|
||||
AuthEmailRegisterSubmitted: "loadingEmailRegister",
|
||||
AuthGoogleLoginSubmitted: "loadingOAuth",
|
||||
AuthFacebookLoginSubmitted: "loadingOAuth",
|
||||
AuthAppleLoginSubmitted: {
|
||||
actions: assign({
|
||||
errorMessage: "Apple login not implemented",
|
||||
}),
|
||||
},
|
||||
|
||||
// OAuth 回调后 sync 入口 —— 由 <OAuthSessionSync /> 派发
|
||||
AuthGoogleSyncSubmitted: "syncingGoogleBackend",
|
||||
|
||||
@@ -1,17 +1,11 @@
|
||||
/**
|
||||
* Auth 状态机:State 形状 + 初始值
|
||||
*/
|
||||
import type { AuthMode, AuthPanelMode, LoginStatus } from "@/data/dto/auth";
|
||||
import type { AuthPanelMode, LoginStatus } from "@/data/dto/auth";
|
||||
|
||||
export interface AuthState {
|
||||
/** 当前面板模式(Facebook / Email) */
|
||||
authPanelMode: AuthPanelMode;
|
||||
/** 内部登录模式(login / register) */
|
||||
authMode: AuthMode;
|
||||
email: string;
|
||||
password: string;
|
||||
username: string;
|
||||
confirmPassword: string;
|
||||
errorMessage: string | null;
|
||||
/** 当前登录状态(未登录 / 游客 / OAuth / 邮箱)—— 下游同步器监听此字段的双向变化 */
|
||||
loginStatus: LoginStatus;
|
||||
@@ -21,11 +15,6 @@ export interface AuthState {
|
||||
|
||||
export const initialState: AuthState = {
|
||||
authPanelMode: "facebook",
|
||||
authMode: "login",
|
||||
email: "",
|
||||
password: "",
|
||||
username: "",
|
||||
confirmPassword: "",
|
||||
errorMessage: null,
|
||||
loginStatus: "notLoggedIn",
|
||||
hasInitialized: false,
|
||||
|
||||
Reference in New Issue
Block a user