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:
2026-06-10 18:58:15 +08:00
parent 744e23fc29
commit 47591be41c
30 changed files with 111 additions and 117 deletions
+3 -3
View File
@@ -20,13 +20,13 @@ import {
} from "react";
import { useMachine } from "@xstate/react";
import { chatMachine } from "./chat-machine";
import type { ChatEvent, ChatContext as MachineContext } from "./chat-machine";
import { chatMachine } from "./machine/chat-machine";
import type { ChatEvent, ChatState as MachineContext } from "./machine/chat-machine";
/**
* 对外暴露的 State 形状(保持与原 ChatState 兼容)
*/
export interface ChatState {
interface ChatState {
messages: MachineContext["messages"];
isReplyingAI: boolean;
isGuest: boolean;
+1 -1
View File
@@ -8,5 +8,5 @@
* - `ChatState` 由 `chat-context.tsx` 导出(保持原 API 兼容)
* - `GuestChatQuota` 仍由 `chat-machine.ts` 导出(业务常量,与上下文配对紧密)
*/
export type { ChatEvent } from "./chat-events";
export type { ChatEvent } from "./machine/chat-events";
export { GuestChatQuota } from "./chat-machine";
+2 -1
View File
@@ -11,7 +11,8 @@
* 注:chat-side-effects.ts 暂未删除(其中 WebSocket 长生命周期逻辑
* 待下一轮迁移到 fromCallback actor)。
*/
export * from "./machine/chat-state";
export * from "./chat-context";
export * from "./chat-events";
export * from "./machine/chat-events";
export * from "./chat-types";
export { chatMachine } from "./chat-machine";
@@ -23,8 +23,8 @@ import { AuthStorage } from "@/data/storage/auth/auth_storage";
import { formatDate } from "@/utils/date";
import { Result } from "@/utils/result";
import { ChatContext, initialContext } from "./chat-context";
import type { ChatEvent } from "./chat-events";
import { ChatState, initialState } from "./chat-state";
import type { ChatEvent } from "./machine/chat-events";
/** 游客配额阈值(与 Dart `GuestChatQuota` 保持一致) */
export const GuestChatQuota = {
@@ -32,10 +32,10 @@ export const GuestChatQuota = {
quotaExhausted: 0,
} as const;
// 重新导出 Context / Event 类型,保持 machine 文件的公共 API 不变
export type { ChatContext } from "./chat-context";
export { initialContext } from "./chat-context";
export type { ChatEvent } from "./chat-events";
// 重新导出 State / Event 类型,保持 machine 文件的公共 API 不变
export type { ChatState } from "./chat-state";
export { initialState } from "./chat-state";
export type { ChatEvent } from "./machine/chat-events";
// ============================================================
// Helpers
@@ -146,7 +146,7 @@ const loadMoreHistoryActor = fromPromise<
// ============================================================
export const chatMachine = setup({
types: {
context: {} as ChatContext,
context: {} as ChatState,
events: {} as ChatEvent,
},
actors: {
@@ -230,7 +230,7 @@ export const chatMachine = setup({
}).createMachine({
id: "chat",
initial: "idle",
context: initialContext,
context: initialState,
states: {
idle: {
on: {
@@ -1,11 +1,11 @@
/**
* Chat Context +
* Chat State +
*
* GuestChatQuota chat-machine.ts
*/
import type { UiMessage } from "@/models/chat/ui-message";
export interface ChatContext {
export interface ChatState {
messages: UiMessage[];
isReplyingAI: boolean;
isGuest: boolean;
@@ -17,7 +17,7 @@ export interface ChatContext {
historyOffset: number;
}
export const initialContext: ChatContext = {
export const initialState: ChatState = {
messages: [],
isReplyingAI: false,
isGuest: true,