React
This guide covers integrating @daveyplate/better-auth-ui
into your React project.
Setting up AuthUIProvider
First, set up <AuthUIProvider>
as it provides context and hooks required by all subsequent authentication components. Create a top-level provider to encapsulate your app:
Wrap your root component with the newly created Providers component in your main app entry point, typically in src/main.tsx
or src/index.tsx
.
Creating Auth Pages
Configure routes to render <AuthCard>
for authentication views using React Router.
Create a dynamic authentication route such as auth/[pathname].tsx
inside your src
directory. Here's a recommended setup:
Use React Router to configure these dynamic authentication routes:
The dynamic segment [pathname]
covers the following default authentication views:
/auth/sign-in
– Sign in via email, password, social providers, or passkey (WebAuthn)/auth/sign-up
– New account registration, with additional fields supported/auth/magic-link
– Email login without password/auth/forgot-password
– Trigger password reset email/auth/reset-password
– Allow users to reset forgotten passwords/auth/sign-out
– Log out action/auth/settings
– User account management page (authentication required)/auth/callback
– Internal OAuth/Auth callback handler (do not use directly)
Your authentication flow is now completely set up and supporting full customization capabilities.