An opinionated SvelteKit 2 + Svelte 5 starter for Firebase-authenticated apps. Includes production-ready auth flows, shadcn-svelte UI, Tailwind CSS v4, and server-side sessions synced with Firebase.
/api/auth/login & /api/auth/logout, protected routes in src/hooks.server.tsusers/{uid} profiles hydrating userProfile storelib/components/ui (add more via CLI)src/app.css with dark-mode defaultssvelte-package tooling| Tool | Version / Notes |
|---|---|
| SvelteKit | @sveltejs/kit@^2.47.1, Svelte 5 runes |
| Styling | Tailwind CSS v4, tw-animate-css, shadcn-svelte |
| Auth & Data | Firebase Web SDK (client) + Admin & Firestore (server) |
| State | Svelte stores (src/lib/stores/userStore.ts) |
| Tooling | Vite 7, TypeScript 5.9, ESLint 9, Prettier 3, svelte-package |
git clone <repo-url> sv-starter
cd sv-starter
npm install
cp env.example .env
.envnpm run dev -- --openClient (VITE_ prefix) and server secrets:
| Variable | Description |
|---|---|
VITE_FIREBASE_API_KEY |
Web API key |
VITE_FIREBASE_AUTH_DOMAIN |
<project>.firebaseapp.com |
VITE_FIREBASE_PROJECT_ID |
Firebase project ID |
VITE_FIREBASE_STORAGE_BUCKET |
Optional |
VITE_FIREBASE_MESSAGING_SENDER_ID |
From Firebase console |
VITE_FIREBASE_APP_ID |
Web app App ID |
FIREBASE_PROJECT_ID |
Same as above (Admin SDK) |
FIREBASE_CLIENT_EMAIL |
Service account email |
FIREBASE_PRIVATE_KEY |
Multi-line private key (\n preserved) |
Never commit .env. Use secrets in CI/CD.
http://localhost:5173 and production domains)users/{uid} with { uid, email, firstName, lastName, emailVerified, createdAt, updatedAt }.envrules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
}
| Command | Purpose |
|---|---|
npm run dev |
Start dev server (http://localhost:5173) |
npm run build |
Build app + package src/lib |
npm run preview |
Preview production build |
npm run check / check:watch |
Type-check with svelte-check |
npm run lint |
Run Prettier + ESLint |
npm run format |
Format with Prettier |
npm run prepack |
Package components (svelte-package + publint) |
Export modules from src/lib/index.ts before prepack if publishing.
| Path | Purpose |
|---|---|
/ |
Marketing splash |
/account |
Sign-up (email/password + Google) |
/login |
Login (email/password + Google + reset) |
/reset-password |
Request password reset |
/verify-email |
Email verification polling |
/app |
Protected area (shows userProfile, sign-out) |
/api/auth/login |
Exchange ID token for session cookie + seed Firestore |
/api/auth/logout |
Clear session cookie |
Routes protected in src/hooks.server.ts: verifies session cookie, stores claims on event.locals.user, redirects unverified/unauthenticated users.
src/lib/firebase/auth.ts helpersensureServerSession POSTs to /api/auth/login after Firebase authsession cookie, upserts Firestore profilesrc/hooks.server.ts reads cookie for SSR-aware authsrc/routes/app/+layout.server.ts) fetch Firestore profile, expose via userProfile storecomponents.json, add components with npx shadcn-svelte@latest add <component>src/app.csssrc/lib/components/blocks/auth (forms, validation, loading states)src/lib/stores/userStore.ts (userProfile + loading)bodyClassUpdater.ts (body classes), firebase-admin.ts (Admin SDK init)src/routes/app/... (auth context provided by +layout)Uses @sveltejs/adapter-auto. Choose adapter for your host (adapter-node, adapter-vercel, adapter-cloudflare, etc.). Configure Firebase secrets in hosting environment, ensure HTTPS-only cookies in production.