refactor(auth): unify Facebook and Google login into AuthPlatform class
Replace the separate FacebookLogin and GoogleLogin classes with a single
AuthPlatform class that takes a provider name ("facebook" | "google") as a
constructor argument. This consolidates duplicate OAuth sign-in logic behind
one entry point while preserving the existing NextAuth flow.
- Add new src/lib/auth/auth_platform.ts exporting AuthPlatform and
AuthProvider type
- Update auth-facebook-panel.tsx and splash-button.tsx to use the new API
- Rename initialContext → initialState in the auth machine for consistency
- Update inline docs and comments to reference AuthPlatform
No behavioral change for end users; both providers still route through
NextAuth's signIn() with the same callbacks and cookies.
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
* - Context 形状与初始值位于 user-context.ts
|
||||
* - 事件联合位于 user-events.ts
|
||||
*/
|
||||
export * from "./machine/user-state";
|
||||
export * from "./user-context";
|
||||
export * from "./user-events";
|
||||
export * from "./machine/user-events";
|
||||
export * from "./user-types";
|
||||
export { userMachine } from "./user-machine";
|
||||
|
||||
@@ -17,13 +17,13 @@ import { authRepository } from "@/data/repositories/auth_repository";
|
||||
import { UserStorage } from "@/data/storage/user/user_storage";
|
||||
import { Result } from "@/utils/result";
|
||||
|
||||
import { UserContext, initialContext } from "./user-context";
|
||||
import type { UserEvent } from "./user-events";
|
||||
import { UserState, initialState } from "./machine/user-state";
|
||||
import type { UserEvent } from "./machine/user-events";
|
||||
|
||||
// 重新导出 Context / Event 类型,保持 machine 文件的公共 API 不变
|
||||
export type { UserContext } from "./user-context";
|
||||
export { initialContext } from "./user-context";
|
||||
export type { UserEvent } from "./user-events";
|
||||
// 重新导出 State / Event 类型,保持 machine 文件的公共 API 不变
|
||||
export type { UserState } from "./machine/user-state";
|
||||
export { initialState } from "./machine/user-state";
|
||||
export type { UserEvent } from "./machine/user-events";
|
||||
|
||||
// ============================================================
|
||||
// Helpers
|
||||
@@ -102,7 +102,7 @@ const userLogoutActor = fromPromise<void>(async () => {
|
||||
// ============================================================
|
||||
export const userMachine = setup({
|
||||
types: {
|
||||
context: {} as UserContext,
|
||||
context: {} as UserState,
|
||||
events: {} as UserEvent,
|
||||
},
|
||||
actors: {
|
||||
@@ -136,7 +136,7 @@ export const userMachine = setup({
|
||||
}).createMachine({
|
||||
id: "user",
|
||||
initial: "idle",
|
||||
context: initialContext,
|
||||
context: initialState,
|
||||
states: {
|
||||
idle: {
|
||||
on: {
|
||||
@@ -1,9 +1,9 @@
|
||||
/**
|
||||
* User 状态机:Context 形状 + 初始值
|
||||
* User 状态机:State 形状 + 初始值
|
||||
*/
|
||||
import type { UserView } from "@/models/user/user";
|
||||
|
||||
export interface UserContext {
|
||||
export interface UserState {
|
||||
currentUser: UserView | null;
|
||||
pronouns: string;
|
||||
coinBalance: number;
|
||||
@@ -11,7 +11,7 @@ export interface UserContext {
|
||||
avatarUrl: string | null;
|
||||
}
|
||||
|
||||
export const initialContext: UserContext = {
|
||||
export const initialState: UserState = {
|
||||
currentUser: null,
|
||||
pronouns: "He",
|
||||
coinBalance: 45,
|
||||
@@ -18,12 +18,12 @@ import {
|
||||
import { useMachine } from "@xstate/react";
|
||||
|
||||
import { userMachine } from "./user-machine";
|
||||
import type { UserContext as MachineContext, UserEvent } from "./user-machine";
|
||||
import type { UserState as MachineContext, UserEvent } from "./user-machine";
|
||||
|
||||
/**
|
||||
* 对外暴露的 State 形状(保持与原 UserState 兼容)
|
||||
*/
|
||||
export interface UserState {
|
||||
interface UserState {
|
||||
currentUser: MachineContext["currentUser"];
|
||||
pronouns: string;
|
||||
coinBalance: number;
|
||||
|
||||
@@ -7,4 +7,4 @@
|
||||
* - Context 形状与初始值由 `user-context.ts` 导出
|
||||
* - `UserState` 由 `user-context.tsx` 导出(保持原 API 兼容)
|
||||
*/
|
||||
export type { UserEvent } from "./user-events";
|
||||
export type { UserEvent } from "./machine/user-events";
|
||||
|
||||
Reference in New Issue
Block a user