thc-sveltekit-better-auth Svelte Themes

Thc Sveltekit Better Auth

demonstration of Real Authentication in SvelteKit with better-auth

Better Auth Demo for SvelteKit

This project demonstrates a robust authentication setup in SvelteKit using the better-auth library. It covers login, registration, session management, and secure navigation patterns for modern SvelteKit apps.

Features

  • Email/password authentication
  • Session management with cookies
  • Reactive auth context using Svelte 5 runes
  • Secure navigation and invalidation
  • Example dashboard and protected routes
  • Clean, modern UI components

Getting Started

Prerequisites

  • Node.js (v18+ recommended)
  • pnpm (recommended)

Database setup

This demo uses a simple SQL database for user storage. You can use any SQL database (PostgreSQL, MySQL, SQLite, etc.) that you prefer.

  • The schema is in db/schema.sql. Use your preferred SQL database and apply the schema.
  • Configure your database connection in environment variables as needed.

Build for production

pnpm run build

Project Structure

  • src/lib/auth/ — Auth context and helpers
  • src/lib/client/auth.ts — Client-side auth API
  • src/lib/components/ — UI components (Nav, LogoutButton)
  • src/routes/ — SvelteKit routes (login, register, dashboard)
  • db/schema.sql — Database schema

License

MIT — free to use, adapt, and ship.


Made with ❤️ with SvelteKit and better-auth

Top categories

Loading Svelte Themes