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 {
|
||||
|
||||
Reference in New Issue
Block a user