refactor(auth): remove AuthGate abstraction in favor of useSession
- Drop AuthGate/AuthGateState re-exports from @/lib/auth/nextauth - Simplify SplashButton by removing skipHref prop and hardcoding ROUTES.chat - Update comments to reference useSession() (next-auth/react) directly instead of the AuthGate wrapper, since the auth UI gate no longer needs the extra abstraction layer.
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
"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) };
|
||||
}
|
||||
}
|
||||
@@ -43,9 +43,8 @@ export { handler as GET, handler as POST };
|
||||
// 每个 class 一个独立文件,详见同目录的子模块。
|
||||
// 这里 re-export 仅为消费者提供 `@/lib/auth/nextauth` 单点导入。
|
||||
// 注:上方 `next-auth` 是 server-only,本文件编译时会被 Next.js 切分到 server bundle;
|
||||
// 客户端 import `GoogleLogin` / `FacebookLogin` / `Logout` / `AuthGate` 时不会拉入。
|
||||
// 客户端 import `GoogleLogin` / `FacebookLogin` / `Logout` 时不会拉入。
|
||||
// ============================================================
|
||||
export { GoogleLogin } from "./google_login";
|
||||
export { FacebookLogin } from "./facebook_login";
|
||||
export { Logout } from "./logout";
|
||||
export { AuthGate, type AuthGateState } from "./auth_gate";
|
||||
|
||||
Reference in New Issue
Block a user