ES

@yohangel / auth-react

1.0.0 ▾
MIT
GitHub

UI de login en React para Better Auth: inicio de sesión con 2FA, registro, botones sociales y hooks

Código6 archivosContexto~468 tokensescaneo superado

El árbol exacto que se inyectará, tras aplicar .genpmignore. Anclado a

src/lib/auth-react/guard.tsxsolo lectura · 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>
  );
}

Reportar @yohangel/auth-react

Inicia sesión con GitHub para reportar un paquete.