Files
cozsweet-frontend-nextjs/src/lib/auth/auth_gate.ts
T
admin d70e61f92e 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)`.
2026-06-10 15:34:52 +08:00

29 lines
744 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"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) };
}
}