Skip to content

Simple Demo of Lucia Auth using Drizzle ORM, Turso Tech (SQLite) & Resend (Transactional Emails) to make Magic Link Authentication work

Notifications You must be signed in to change notification settings

deadcoder0904/next-13-lucia-auth-drizzle-turso-sqlite-magic-link

Repository files navigation

next-13-lucia-auth-drizzle-turso-sqlite-magic-link

Installation

  1. Install Turso on your machine:
curl -sSfL https://get.tur.so/install.sh | bash
  1. Verify the installation:
turso --version

Generate Auth Token

  1. Use the auth command to start the login process. The command launches your default browser and prompts you to log in with GitHub:
turso auth login
  1. Create a new Turso database:
turso db create magic-link
  1. Create an auth token to get access to your database using libSQL. Copy the auth token to Clipboard.
turso db tokens create magic-link

Store Environment Variables

  1. Change the .env file to use the Turso database
cp .env.example .env # duplicate .env.example & name it .env
  1. Paste the generated auth token above in .env file next to TURSO_AUTH_TOKEN:
TURSO_AUTH_TOKEN=[paste-the-generated-auth-token-without-brackets]
  1. Run this command to get the database URL:
turso db show magic-link --url
  1. Paste the generated url above in .env file next to TURSO_URL:
TURSO_URL=libsql://[your-database]-[your-github].turso.io

Install the dependencies

pnpm install

Start the server

pnpm start

Push schema changes to database

pnpm db:push

Generate Migrations

pnpm db:generate

Flow

  1. /api/signup -> if email already exists, return 400 error. if not, then send magic link via email & redirect to /verify-email page with further instructions

  2. /api/login -> if email doesn't exist in the database, return 400 error. if not, then send magic link via email & redirect to /verify-email page with further instructions

  3. /api/verify-email -> if magic link is clicked inside email, then verify email on /api/verify-email. finally, create lucia session & redirect to /dashboard

  4. /api/logout -> if logout button is clicked, then invalidate all sessions & redirect to /login

  5. redirect from /, /login, /signup, /check-email to /dashboard if session exists.

  6. redirect from /dashboard to /login if session doesn't exist.

About

Simple Demo of Lucia Auth using Drizzle ORM, Turso Tech (SQLite) & Resend (Transactional Emails) to make Magic Link Authentication work

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published