refactor(auth): switch to class-based social login and v4 route handler

Migrate from function-based social login helpers (`facebookLogin`, `googleLogin`)
to class-based services (`new FacebookLogin().signIn()`, `new GoogleLogin().signIn()`),
updating call sites in `AuthFacebookPanel` and `SplashButton` with try/catch error
handling. The NextAuth route handler is also refactored to the v4 pattern, importing
pre-built `GET` / `POST` exports from `@/lib/auth/nextauth` instead of constructing
the handler inline with `NextAuth(authOptions)`.
This commit is contained in:
2026-06-10 15:34:52 +08:00
parent 90bb711a45
commit d70e61f92e
115 changed files with 9004 additions and 493 deletions
@@ -7,13 +7,13 @@
* 视觉规格(与 Dart 对齐):
* - Spacer → logo120h)→ Spacer → Facebook 主按钮 → 链接 → Spacer → 法律
* - Facebook 主按钮:46px 白胶囊 + Facebook "f" 图标(#1877f2+ "Login with Facebook"
* - 社交登录走 NextAuth`facebookLogin()` / `googleLogin()`
* - 社交登录走 NextAuth`new FacebookLogin().signIn()` / `new GoogleLogin().signIn()`
* - "Other Sign-in Options" 链接打开底部弹层
* - 弹层 Email 按钮 → 触发 `onSwitchToEmail`(父级派发 `AuthPanelModeChanged`
*/
import { useState } from "react";
import { facebookLogin, googleLogin } from "@/lib/auth/nextauth";
import { FacebookLogin, GoogleLogin } from "@/lib/auth/nextauth";
import { AuthErrorMessage } from "./auth-error-message";
import { AuthLegalText } from "./auth-legal-text";
@@ -32,17 +32,25 @@ export function AuthFacebookPanel({ onSwitchToEmail }: AuthFacebookPanelProps) {
const handleFacebook = async () => {
setBusy("facebook");
setError(null);
const r = await facebookLogin();
setBusy(null);
if (!r.success) setError(r.error?.message ?? "Facebook login failed");
try {
await new FacebookLogin().signIn();
} catch (e) {
setError(e instanceof Error ? e.message : "Facebook login failed");
} finally {
setBusy(null);
}
};
const handleGoogle = async () => {
setBusy("google");
setError(null);
const r = await googleLogin();
setBusy(null);
if (!r.success) setError(r.error?.message ?? "Google login failed");
try {
await new GoogleLogin().signIn();
} catch (e) {
setError(e instanceof Error ? e.message : "Google login failed");
} finally {
setBusy(null);
}
};
return (