Better Auth UI for Svelte 5

0.12.4 · active · verified Wed Apr 22

better-auth-ui-svelte provides pre-built, customizable authentication UI components designed specifically for integration with the Better Auth backend in Svelte 5 applications. Currently at version 0.12.4, this library is in active early stage development, cautioning users that it is not yet battle-tested in production environments and issues may arise before a v1.0 stable release. The package aims for a rapid iteration cycle, with minor and patch releases occurring frequently as seen in its recent history (multiple patch and minor releases within months). A key differentiator is its full feature parity with the original Better Auth UI React library, leveraging Svelte 5 runes and modern practices, while also introducing Svelte-specific utilities like path helpers. It is styled with Tailwind CSS v4 and built upon shadcn-svelte components, offering extensive customization options out-of-the-box. The library supports Zod 4 for form validation and is localization-ready, but users should be aware that this Svelte port may diverge from the React version's API and features over time.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates setting up the Better Auth client, integrating Tailwind CSS, and using fundamental UI components like `AuthLayout`, `UserButton`, and `ChangeEmailCard` in a SvelteKit project.

import { SvelteKitAuth } from 'better-auth/client';
import { AuthLayout, UserButton, ChangeEmailCard } from 'better-auth-ui-svelte';

// In src/lib/auth.ts (or similar)
export const auth = new SvelteKitAuth({
  apiEndpoint: '/api/auth'
});

// In src/routes/+layout.svelte
<script lang="ts">
  import { onMount } from 'svelte';
  import '../app.css'; // Your global CSS with Tailwind imports
  import { auth } from '$lib/auth';

  onMount(() => {
    // Initialize auth client if needed, or ensure stores are reactive
  });
</script>

<AuthLayout>
  <UserButton />
</AuthLayout>

<!-- In src/routes/settings/email/+page.svelte -->
<script lang="ts">
  import { auth } from '$lib/auth';
</script>

<ChangeEmailCard auth={auth} />

view raw JSON →