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:
@@ -7,13 +7,13 @@
|
||||
* 视觉规格(与 Dart 对齐):
|
||||
* - Spacer → logo(120h)→ Spacer → Facebook 主按钮 → 链接 → Spacer → 法律
|
||||
* - Facebook 主按钮:46px 白胶囊 + Facebook "f" 图标(#1877f2)+ "Login with Facebook"
|
||||
* - 社交登录走 NextAuth:`new FacebookLogin().signIn()` / `new GoogleLogin().signIn()`
|
||||
* - 社交登录走 NextAuth:`new AuthPlatform("facebook").signIn()` / `new AuthPlatform("google").signIn()`
|
||||
* - "Other Sign-in Options" 链接打开底部弹层
|
||||
* - 弹层 Email 按钮 → 触发 `onSwitchToEmail`(父级派发 `AuthPanelModeChanged`)
|
||||
*/
|
||||
import { useState } from "react";
|
||||
|
||||
import { FacebookLogin, GoogleLogin } from "@/lib/auth/nextauth";
|
||||
import { AuthPlatform } from "@/lib/auth/nextauth";
|
||||
|
||||
import { AuthErrorMessage } from "./auth-error-message";
|
||||
import { AuthLegalText } from "./auth-legal-text";
|
||||
@@ -33,7 +33,7 @@ export function AuthFacebookPanel({ onSwitchToEmail }: AuthFacebookPanelProps) {
|
||||
setBusy("facebook");
|
||||
setError(null);
|
||||
try {
|
||||
await new FacebookLogin().signIn();
|
||||
await new AuthPlatform("facebook").signIn();
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Facebook login failed");
|
||||
} finally {
|
||||
@@ -45,7 +45,7 @@ export function AuthFacebookPanel({ onSwitchToEmail }: AuthFacebookPanelProps) {
|
||||
setBusy("google");
|
||||
setError(null);
|
||||
try {
|
||||
await new GoogleLogin().signIn();
|
||||
await new AuthPlatform("google").signIn();
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Google login failed");
|
||||
} finally {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user