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
@@ -11,7 +11,7 @@
* - 消费 `useChatDispatch` / `useUserDispatch`(登录成功后初始化)
* - 自管路由跳转(已登录 / 登录成功 → /chat)
* - Skip 用 `<Link>` 保留 SPA 体验
* - 社交登录按钮走 `new FacebookLogin().signIn()`NextAuth 流程)
* - 社交登录按钮走 `new AuthPlatform("facebook").signIn()`NextAuth 流程)
*/
import Link from "next/link";
import { useRouter } from "next/navigation";
@@ -20,7 +20,7 @@ import { useEffect, useRef } from "react";
import { useAuthState } from "@/stores/auth/auth-context";
import { useChatDispatch } from "@/stores/chat/chat-context";
import { useUserDispatch } from "@/stores/user/user-context";
import { FacebookLogin } from "@/lib/auth/nextauth";
import { AuthPlatform } from "@/lib/auth/nextauth";
import { ROUTES } from "@/router/routes";
import { LoadingIndicator } from "@/app/_components/core/loading-indicator";
import styles from "./splash-button.module.css";
@@ -53,7 +53,7 @@ export function SplashButton() {
const handleFacebookLogin = async () => {
try {
await new FacebookLogin().signIn();
await new AuthPlatform("facebook").signIn();
} catch (e) {
console.error("[splash-button] Facebook login failed", e);
}