A modern authentication-ready SvelteKit project using Better Auth, Drizzle ORM, and Tailwind CSS.
- Frontend: SvelteKit (Svelte 5 with runes)
- Styling: Tailwind CSS with typography and forms plugins
- Authentication: Better Auth with social providers
- Database: PostgreSQL with Drizzle ORM
- Testing: Vitest for unit tests, Playwright for e2e testing
- Development Tools: TypeScript, ESLint, Prettier, Bun runtime
- Bun 1.x or newer (or Node.js 18.x+)
- Docker (for local PostgreSQL)
- GitHub and/or Google OAuth credentials
# Clone the repository
git clone https://github.com/Jpisnice/SvelteKit-BetterAuth-Starter.git
cd SvelteKit-BetterAuth-Starter
# Install dependencies using Bun
bun install
# Or using npm
npm install
Create a .env
file based on the provided .env.example
:
# Copy example environment variables
cp .env.example .env
Update the following values in your .env
file:
BETTER_AUTH_SECRET
: Generate a strong random stringGITHUB_CLIENT_ID
&GITHUB_CLIENT_SECRET
: From GitHub OAuth AppsGOOGLE_CLIENT_ID
&GOOGLE_CLIENT_SECRET
: From Google Cloud Console
# Start the PostgreSQL database using Docker
bun db:start # or: npm run db:start
# Push the schema to the database
bun db:push # or: npm run db:push
# Start the development server with Bun
bun dev
# Or start with the browser opening automatically
bun dev -- --open
# Using npm instead
# npm run dev
# npm run dev -- --open
# Start the database
bun db:start # or: npm run db:start
# View database with Drizzle Studio
bun db:studio # or: npm run db:studio
# Apply migrations
bun db:migrate # or: npm run db:migrate
# Run unit tests
bun test:unit # or: npm run test:unit
# Run e2e tests
bun test:e2e # or: npm run test:e2e
# Run all tests
bun test # or: npm test
# Build for production
bun run build # or: npm run build
# Preview the production build locally
bun preview # or: npm run preview
This project uses Better Auth with GitHub and Google OAuth providers. Users can sign in via:
/login
- Sign in page with social providers- The session is accessible throughout the application
- Go to GitHub → Settings → Developer Settings → OAuth Apps → New OAuth App
- Fill in the application details:
- Application name: Your app name
- Homepage URL:
http://localhost:5173
(for development) - Authorization callback URL:
http://localhost:5173/api/auth/callback/github
- Click "Register Application"
- Copy the Client ID and generate a new Client Secret
- Add these to your
.env
file asGITHUB_CLIENT_ID
andGITHUB_CLIENT_SECRET
- Go to the Google Cloud Console
- Create a new project or select an existing one
- Navigate to "APIs & Services" → "Credentials"
- Click "Create Credentials" → "OAuth client ID"
- Configure the consent screen if prompted
- For application type, select "Web application"
- Add authorized redirect URIs:
http://localhost:5173/api/auth/callback/google
(for development)
- Click "Create"
- Copy the Client ID and Client Secret
- Add these to your
.env
file asGOOGLE_CLIENT_ID
andGOOGLE_CLIENT_SECRET
For production deployment, make sure to update the callback URLs to your production domain.
The project is configured with Tailwind CSS and includes the following plugins:
@tailwindcss/forms
- Better form styling@tailwindcss/typography
- Rich text content styling
The database schema is defined in src/lib/server/db/schema.ts
. After making changes to the schema, run:
bun db:push # or: npm run db:push
- Make sure to keep your
.env
file secure and not commit it to version control - For production, set these variables in your hosting platform's environment settings
- Faster installation times compared to npm
- Improved development server startup speed
- Enhanced testing performance
- If authentication isn't working, verify your OAuth credentials and callback URLs
- For database issues, check Docker is running and the connection string is correct
- If Bun has compatibility issues with any packages, try using Node.js/npm as a fallback
To deploy your app, you may need to install an adapter for your target environment.