Skip to content

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages