sveltekit-better-auth-starter Svelte Themes

Sveltekit Better Auth Starter

SvelteKit BetterAuth Starter

A modern authentication starter template built with SvelteKit and Better Auth, featuring a beautiful UI powered by Tailwind CSS and shadcn-svelte components.

Features

  • šŸ” Secure authentication with Better Auth
    • Email/Password authentication
    • Google OAuth integration
    • Session management
    • Protected routes
  • šŸŽØ Modern UI with shadcn-svelte components
  • šŸŽÆ Type-safe database with Drizzle ORM
  • šŸš€ Fast development with Bun
  • šŸ“± Responsive design with Tailwind CSS
  • ✨ Code quality tools:
    • TypeScript for type safety
    • ESLint for code linting
    • Prettier for code formatting

Prerequisites

  • Bun (v1.0.0 or higher)
  • PostgreSQL database
  • Google OAuth credentials (for social login)

Getting Started

  1. Clone the repository:

    git clone https://github.com/yourusername/sveltekit-better-auth-starter.git
    cd sveltekit-better-auth-starter
    
  2. Install dependencies:

    bun install
    
  3. Create a .env file in the root directory:

    DATABASE_URL=postgresql://user:password@localhost:5432/your_database
    GOOGLE_CLIENT_ID=your_google_client_id
    GOOGLE_CLIENT_SECRET=your_google_client_secret
    
  4. Push the database schema:

    bun run db:push
    
  5. Start the development server:

    bun run dev
    

Visit http://localhost:5173 to see your application running.

Project Structure

sveltekit-better-auth-starter/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ lib/
│   │   ā”œā”€ā”€ components/     # UI components
│   │   ā”œā”€ā”€ database/       # Database schema and configuration
│   │   ā”œā”€ā”€ server/         # Server-side authentication logic
│   │   └── hooks/         # Custom SvelteKit hooks
│   └── routes/            # SvelteKit routes
ā”œā”€ā”€ static/               # Static assets
└── [Configuration files]

Authentication Flow

  1. Users can sign up using email/password or Google OAuth
  2. On successful authentication, a session is created
  3. Protected routes (e.g., /dash) require valid session
  4. Users can sign out to invalidate their session

Database Schema

The project uses Drizzle ORM with PostgreSQL and includes the following tables:

  • users: User information
  • sessions: Active sessions
  • accounts: OAuth accounts
  • verifications: Email verification tokens

Development

  • bun run dev - Start development server
  • bun run build - Build for production
  • bun run preview - Preview production build
  • bun run lint - Run ESLint
  • bun run format - Format code with Prettier
  • bun run db:push - Push database schema changes
  • bun run db:studio - Open Drizzle Studio

Deployment

This project is configured for deployment on Vercel using the SvelteKit adapter. Make sure to:

  1. Set up your environment variables in your deployment platform
  2. Configure your PostgreSQL database
  3. Deploy your application

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Top categories

Loading Svelte Themes