d70e61f92e
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)`.
29 lines
744 B
TypeScript
29 lines
744 B
TypeScript
"use client";
|
||
/**
|
||
* 客户端鉴权门(class-oriented 封装)
|
||
*
|
||
* `useState` 是 static 方法而非实例方法(hooks 必须在 React 函数组件中调用,
|
||
* static 方法本质上仍由组件调用,hook 链合法)。调用方写法:
|
||
*
|
||
* ```tsx
|
||
* function MyComponent() {
|
||
* const { isAuthed } = AuthGate.useState();
|
||
* }
|
||
* ```
|
||
*
|
||
* 原始 Dart: nextauth-helpers.useAuthGate()
|
||
*/
|
||
import { useSession } from "next-auth/react";
|
||
|
||
export interface AuthGateState {
|
||
isAuthed: boolean;
|
||
}
|
||
|
||
export class AuthGate {
|
||
/** 必须在 React 函数组件内调用(useSession 是 hook) */
|
||
static useState(): AuthGateState {
|
||
const { data: session } = useSession();
|
||
return { isAuthed: Boolean(session?.user) };
|
||
}
|
||
}
|