Better Auth UI: Plug & Play Shadcn/UI Components
better-auth-ui is a comprehensive React component library providing plug-and-play authentication UIs built on `shadcn/ui` for the `better-auth` ecosystem. Currently at version 3.2.27, it delivers a suite of pre-built, highly customizable components covering common authentication flows such as sign-in, sign-up, password recovery, user profile management, and settings. The library aims to streamline the development of secure and aesthetically pleasing authentication interfaces by leveraging `shadcn/ui` for styling, `react-hook-form` for form management, and `@tanstack/react-query` for data fetching. It ships with full TypeScript support, ensuring type safety and a robust developer experience. While a specific release cadence isn't detailed, the consistent versioning indicates active development, focusing on integration with `better-auth` to empower developers to 'Own Your Auth' with minimal setup.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'register')
cause `react-hook-form` context is missing or a component is used outside its intended form context.fixEnsure form components are correctly rendered within a `<form>` element managed by `react-hook-form` and that you have `react-hook-form` installed at a compatible version. -
Error: AuthUIProvider context is missing. Please make sure to wrap your application with <AuthUIProvider>.
cause The `AuthUIProvider` component was not rendered in the parent tree of the `better-auth-ui` component.fixAdd `<AuthUIProvider>` to your application's root layout or entry point, ensuring it wraps all components that utilize `better-auth-ui`. -
Module not found: Can't resolve 'better-auth-ui'
cause The `better-auth-ui` package is not installed or incorrectly referenced in your project.fixRun `npm install better-auth-ui` or `pnpm add better-auth-ui` to install the package. Verify the import path is correct. -
TS2307: Cannot find module 'better-auth-ui' or its corresponding type declarations.
cause TypeScript cannot find the type definitions for the `better-auth-ui` package.fixEnsure `better-auth-ui` is installed, as it ships with its own types. Check your `tsconfig.json` for proper `moduleResolution` and `path` configurations if issues persist.
Warnings
- breaking Upgrading `better-auth` or `@tanstack/react-query` to a new major version might introduce breaking changes that require corresponding updates to `better-auth-ui` or its configuration.
- gotcha Incorrect or incomplete Tailwind CSS configuration will lead to unstyled or improperly styled components, as `better-auth-ui` relies heavily on `shadcn/ui`'s utility-first styling approach.
- gotcha Failure to wrap your application with the `AuthUIProvider` will result in components not functioning correctly or throwing errors related to missing context.
- gotcha Missing or incompatible peer dependencies (e.g., `react-hook-form`, `zod`, various `@radix-ui` packages) can cause runtime errors or build failures.
- breaking Version 3 significantly refactored component APIs and internal structures to better align with `better-auth` v1.5.2+ and modern React practices. Direct imports or props from v2 might no longer be valid.
Install
-
npm install better-auth-ui -
yarn add better-auth-ui -
pnpm add better-auth-ui
Imports
- AuthUIProvider
const { AuthUIProvider } = require('better-auth-ui');import { AuthUIProvider } from 'better-auth-ui'; - SignInCard
import SignInCard from 'better-auth-ui';
import { SignInCard } from 'better-auth-ui'; - SignUpCard
import { SignUpCard } from 'better-auth-ui'; - UserButton
import { UserButton } from 'better-auth-ui';
Quickstart
import { AuthUIProvider, SignInCard } from "better-auth-ui";
import React from 'react';
// In your main layout file, e.g., src/app/layout.tsx (for Next.js App Router)
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
<AuthUIProvider>
{children}
</AuthUIProvider>
</body>
</html>
);
}
// In a page component, e.g., src/app/login/page.tsx
export function LoginPage() {
return (
<div className="flex min-h-screen items-center justify-center p-4">
<SignInCard />
</div>
);
}