SvelteKit-auth-w-Lucia-Postgres-Drizzle-template Svelte Themes

Sveltekit Auth W Lucia Postgres Drizzle Template

This is a SvelteKit template project with the Lucia auth example "Email and password example with 2FA and WebAuthn" implemented, ready to use and extend.

Lucia auth w/ Sveltekit, postgres and Drizzle as template project written in TypeScipt :revolving_hearts:

This is a SvelteKit template project with Lucia auth Email and password example with 2FA and WebAuthn already implemented, ready to use and extend.

It uses nodemailer for sending emails.

I simply followed lucia auth's instructions. I'm definitely not an expert on authorization or anything like that. I just thought it might make life easier for some people.

TODOs :clipboard:

env

Create a .env file. Generate a 128 bit (16 byte) string, base64 encode it, and set it as ENCRYPTION_KEY.

ENCRYPTION_KEY="L9pmqRJnO1ZJSQ2svbHuBA=="

You can use OpenSSL to quickly generate a secure key.

openssl rand --base64 16
  • Add an 'ORIGIN' variable to your env file that corresponds to the hostname (for example "localgost").
  • Add an 'ORIGIN_URL' variable to your env file that corresponds to the host url (for example "http://localhost:5173").

Setup SMTP for sending mails

Setup your SMTP server in the transporter.ts file. You can use Gmail. Insert your gmail as GMAIL_EMAIL and an "app password" as GMAIL_PASSWORD in your env file.

Uncomment and fill in / rewrite the informations for the email-verification process in the email-verification.ts file and password-reset process in the password-reset.ts file.

Setup your postgres database

This project uses Drizzle ORM.

Lucia :smiling_imp:

  • Run npm run db:push to update your database schema
  • Visit /lucia route to view the demo

Drizzle :sweat_drops:

  • You will need to set DATABASE_URL in your production environment
  • Run npm run db:push to update your database schema

Developing

Once you've created a project and installed dependencies with npm install (or pnpm install or yarn), start a development server:

npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open

Building

To create a production version of your app:

npm run build

You can preview the production build with npm run preview.

To deploy your app, you may need to install an adapter for your target environment.

Top categories

Loading Svelte Themes