ZH
测试版翻译

@yohangel / auth-react

1.0.0 ▾
MIT
GitHub

Better Auth 的 React 登录界面:支持双重验证的登录、注册、社交按钮和会话 Hook

代码6 个文件上下文约 468 个 token扫描通过

应用 .genpmignore 后将被注入的确切目录树。固定于

src/lib/auth-react/guard.tsx只读 · 7145b9d
// Guardas de cliente. Solo afectan a lo que se ve: la autorización real siempre se comprueba en el servidor.
import type { ReactNode } from 'react';
import { authClient, useSession } from './client.js';

/** Muestra `children` con sesión; sin ella, `fallback` (p. ej. <SignInForm/> o un enlace a /sign-in). */
export function SignedIn({ children, fallback = null, loading = null }: { children: ReactNode; fallback?: ReactNode; loading?: ReactNode }) {
  const { data, isPending } = useSession();
  if (isPending) return <>{loading}</>;
  return <>{data ? children : fallback}</>;
}

export function SignOutButton({ children = 'Sign out', redirectTo = '/' }: { children?: ReactNode; redirectTo?: string }) {
  return (
    <button
      type="button"
      onClick={() =>
        void authClient.signOut({ fetchOptions: { onSuccess: () => window.location.assign(redirectTo.startsWith('/') ? redirectTo : '/') } })
      }
    >
      {children}
    </button>
  );
}

举报 @yohangel/auth-react

使用 GitHub 登录后才能举报包。