This is an example project showcasing authentication processes using Lucia for state management and Drizzle for ORM (Object-Relational Mapping) in a SvelteKit application.
This project demonstrates how to implement authentication features such as user signup, login, logout, and protected routes using Lucia for state management and Drizzle for ORM.
- User signup: Allow users to create a new account.
- User login: Allow existing users to authenticate themselves.
- User logout: Allow authenticated users to log out of their accounts.
- Protected routes: Restrict access to certain routes to authenticated users only.
-
Clone the repository:
git clone https://github.com/hrasekj/sveltekit-with-lucia-auth.git
-
Navigate into the project directory:
cd sveltekit-auth-example
-
Install dependencies:
pnpm install
-
Use .env.example to create a new .env file:
cp .env.example .env
-
Initialize database:
docker-compose up -d
-
Push migrations to the database:
npx drizzle-kit push:mysql
-
Start the development server:
pnpm dev # or start the server and open the app in a new browser tab pnpm dev --open
-
In browser navigate to http://localhost:5173.
-
Explore the authentication features implemented in the application.
To create new migration files, run:
npx drizzle-kit generate:mysql
Then push the new migration to the database.
- SvelteKit: A framework for building web applications.
- Lucia: Authentication library.
- Drizzle ORM: An ORM (Object-Relational Mapping) library.
Here are some resources that helped me create this project:
- https://blog.robino.dev/posts/svelte-zod-error
- https://dev.to/thiteago/protecting-sveltekit-routes-from-unauthenticated-users-nb9
This project is licensed under the MIT License - see the LICENSE file for details.