"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) }; } }