A template project demonstrating cookie-based authentication in SvelteKit using SQLite for session management.
sveltekitAuthTemplate/
āāā src/
ā āāā routes/
ā ā āāā (marketing)/ # Public routes
ā ā ā āāā login/ # Login/signup pages
ā ā ā āāā +page.svelte # Landing page
ā ā āāā (protected)/ # Auth-required routes
ā ā āāā home/ # User dashboard
ā āāā lib/
ā ā āāā db/ # Database services
ā ā āāā types.ts # TypeScript definitions
ā āāā components/ # Reusable components
ā āāā hooks.server.ts # Auth middleware
āāā static/ # Static assets
Login Process:
Session Management:
Security Features:
Clone the repository
Install dependencies:
npm install
Start the development server:
npm run dev
Visit http://localhost:5173
For testing purposes:
The project uses SQLite with the following tables:
Protected routes are placed in the (protected)
directory and require authentication. The server-side hook automatically checks for valid sessions.
(protected)
directoryevent.locals.user
Modify cookie expiration in database.ts
:
// Default: 1 hour
expireTime: Date.now() + 60 * 60 * 1000
MIT