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:
@@ -11,7 +11,7 @@
|
||||
* - 消费 `useChatDispatch` / `useUserDispatch`(登录成功后初始化)
|
||||
* - 自管路由跳转(已登录 / 登录成功 → /chat)
|
||||
* - Skip 用 `<Link>` 保留 SPA 体验
|
||||
* - 社交登录按钮直接调 `nextauth.facebookLogin()`(NextAuth 流程)
|
||||
* - 社交登录按钮走 `new FacebookLogin().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 { FacebookLogin } from "@/lib/auth/nextauth";
|
||||
import { ROUTES } from "@/router/routes";
|
||||
import { LoadingIndicator } from "@/app/_components/core/loading-indicator";
|
||||
import styles from "./splash-button.module.css";
|
||||
@@ -57,9 +57,10 @@ export function SplashButton({ skipHref = ROUTES.chat }: SplashButtonProps) {
|
||||
}, [state.isSuccess, chatDispatch, userDispatch, router]);
|
||||
|
||||
const handleFacebookLogin = async () => {
|
||||
const r = await facebookLogin();
|
||||
if (!r.success) {
|
||||
console.error("[splash-button] Facebook login failed", r.error);
|
||||
try {
|
||||
await new FacebookLogin().signIn();
|
||||
} catch (e) {
|
||||
console.error("[splash-button] Facebook login failed", e);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user