A production-ready authentication starter with SvelteKit, Better Auth, PostgreSQL, Podman, Supabase, and Cloudflare Pages deployment.
Create a new app from this starter:
# Option 1: Use the create script
cd sveltekit-auth-app
./create-app.sh my-new-app
# Option 2: Manual copy
cp -r sveltekit-auth-app my-new-app
cd my-new-app
rm -rf .git node_modules .svelte-kit
npm install
npm install
Start the PostgreSQL database:
npm run podman:up
This starts:
localhost:5433localhost:8080Create a .env file:
# Local development (Podman PostgreSQL)
DATABASE_URL="postgresql://postgres:postgres@localhost:5433/auth_db"
BETTER_AUTH_SECRET="your-super-secret-key-generate-with-openssl-rand-base64-32"
npm run db:push
npm run dev
Visit http://localhost:5173 š
Run migrations against Supabase:
DATABASE_URL="postgresql://postgres:[PASSWORD]@db.[PROJECT-REF].supabase.co:5432/postgres" npm run db:push
wrangler secret put DATABASE_URL
wrangler secret put BETTER_AUTH_SECRET
npm run build
npm run deploy
Or connect your GitHub repo to Cloudflare Pages for automatic deployments.
npm run build.svelte-kit/cloudflare20āāā src/
ā āāā lib/
ā ā āāā server/
ā ā ā āāā auth.js # Better Auth configuration
ā ā ā āāā db.js # Database connection
ā ā ā āāā schema.js # Drizzle schema
ā ā āāā auth-client.js # Client-side auth
ā āāā routes/
ā ā āāā api/auth/[...all]/ # Auth API endpoints
ā ā āāā login/ # Login page
ā ā āāā register/ # Registration page
ā ā āāā +page.svelte # Landing page
ā āāā hooks.server.js # Session handling
ā āāā app.d.ts # Type definitions
āāā podman-compose.yaml # Local database setup
āāā wrangler.toml # Cloudflare configuration
āāā drizzle.config.js # Drizzle ORM config
āāā create-app.sh # Template scaffolding script
āāā init.sql # Database initialization
| Command | Description |
|---|---|
npm run dev |
Start development server |
npm run build |
Build for production |
npm run preview |
Preview production build |
npm run podman:up |
Start local PostgreSQL |
npm run podman:down |
Stop local PostgreSQL |
npm run podman:logs |
View container logs |
npm run db:generate |
Generate migrations |
npm run db:push |
Push schema to database |
npm run db:studio |
Open Drizzle Studio |
npm run deploy |
Deploy to Cloudflare |
Update src/lib/server/auth.js:
import { betterAuth } from 'better-auth';
export function createAuth(databaseUrl, baseUrl) {
return betterAuth({
// ... existing config
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
},
github: {
clientId: process.env.GITHUB_CLIENT_ID,
clientSecret: process.env.GITHUB_CLIENT_SECRET,
},
},
});
}
Enable in auth config:
emailAndPassword: {
enabled: true,
requireEmailVerification: true,
sendVerificationEmail: async ({ user, url }) => {
// Send email via Resend, SendGrid, etc.
}
}
MIT License - feel free to use this starter for your projects!
Todos