Skip to content
VercelLogotypeVercelLogotype
LoginSign Up

Next.js Lucia Email/Password Auth with Drizzle

Authentication with Lucia including email verification and password reset.

DeployView Demo

Next.js Auth Starter Template

Motivation

Implementing authentication in Next.js, especially Email+Password authentication, can be challenging. NextAuth intentionally limits email password functionality to discourage the use of passwords due to security risks and added complexity. However, in certain projects, clients may require user password authentication. Lucia offers a flexible alternative to NextAuth.js, providing more customization options without compromising on security. This template serves as a starting point for building a Next.js app with Lucia authentication.

Lucia vs. NextAuth.js

Lucia is less opinionated than NextAuth, offering greater flexibility for customization. While Lucia involves more setup, it provides a higher degree of flexibility, making it a suitable choice for projects requiring unique authentication configurations.

Key Features

  • Authentication: ๐Ÿ’ผ Support for Credential and OAuth authentication.
  • Authorization: ๐Ÿ”’ Easily manage public and protected routes within the app directory.
  • Email Verification: ๐Ÿ“ง Verify user identities through email.
  • Password Reset: ๐Ÿ”‘ Streamline password resets by sending email password reset links.
  • Lucia + tRPC: ๐Ÿ”„ Similar to NextAuth with tRPC, granting access to sessions and user information through tRPC procedures.
  • E2E tests: ๐Ÿงช Catch every issue before your users do with comprehensive E2E testing.
  • Stripe Payment: ๐Ÿ’ณ Setup user subscriptions seamlessly with stripe.
  • Email template with react-email: โœ‰๏ธ Craft your email templates using React.
  • PostgreSQL Database: ๐Ÿ›ข๏ธ Utilize a PostgreSQL database set up using Drizzle for enhanced performance and type safety.
  • Database Migration: ๐Ÿš€ Included migration script to extend the database schema according to your project needs.

Tech Stack

  • Next.js
  • Lucia
  • tRPC
  • Drizzle ORM
  • PostgreSQL
  • Stripe
  • Tailwind CSS
  • Shadcn UI
  • React Hook Form
  • React Email
  • Playwright

Get Started

  1. Clone this repository to your local machine.
  2. Copy .env.example to .env and fill in the required environment variables.
  3. Run pnpm install to install dependencies.
  4. (for node v18 or lower): Uncomment polyfills for webCrypto in src/lib/auth/index.ts
  5. Update app title, database prefix, and other parameters in the src/lib/constants.ts file.
  6. Run pnpm db:push to push your schema to the database.
  7. Execute pnpm dev to start the development server and enjoy!

Testing

  1. Install Playwright (use this command if you want to install chromium only pnpm exec playwright install chromium --with-deps)
  2. Build production files using pnpm build
  3. Run pnpm test:e2e (add --debug flag to open tests in browser in debug mode)

Using Github actions

Add the following environment variables to your github actions repository secrets - DATABASE_URL, DISCORD_CLIENT_ID, DISCORD_CLIENT_SECRET

Roadmap

  • Update Password
  • Stripe Integration
  • Admin Dashboard (under consideration)
  • Role-Based Access Policy (under consideration)

Contributing

To contribute, fork the repository and create a feature branch. Test your changes, and if possible, open an issue for discussion before submitting a pull request. Follow project guidelines, and welcome feedback to ensure a smooth integration of your contributions. Your pull requests are warmly welcome.

GitHub
Owneriamtouha
Repositorynext-lucia-auth
Use Cases
Starter
Stack
Next.js
Tailwind

Related Templates

Next.js Boilerplate

Get started with Next.js and React in seconds.
Next.js Boilerplate thumbnail

Chatbot UI

A ChatGPT clone for running locally in your browser.
Chatbot UI thumbnail

Agent Stack

  • AI SDK
  • AI Gateway
  • Sandbox
  • Workflows
  • ConnectNew
  • PassportNew
  • eveNew

Core Platform

  • CI/CD
  • Content Delivery
  • Fluid Compute
  • Observability

Security

  • Platform Security
  • WAF
  • Bot Management
  • Bot ID

Tools

  • Vercel DropNew
  • Vercel Agent
  • Vercel PluginNew
  • Agent Skills
  • Next.js
  • Domains
  • v0

Frameworks

  • eveNew
  • Nuxt
  • SvelteKit
  • Nitro
  • Turborepo
  • Tanstack Start
  • FastAPI
  • xmcp
  • All frameworks

SDKs

  • Vercel SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDKNew
  • Queues SDKNew
  • Streamdown

Build

  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce
  • Platform Engineers
  • Design Engineers

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Articles
  • Community

Explore

  • Customers
  • Marketplace
  • Templates
  • Partner Finder
  • Vercel + AWS

Company

  • About
  • Careers
  • Press
  • Events
  • Startups
  • Shipped on Vercel
  • Open Source Program
  • Enterprise
  • Pricing
  • Help

Legal & Trust

  • Privacy Policy
  • Terms of Service
  • Cookie Policy
  • DPA
  • Acceptable Use Policy
  • Legal (all documents)
  • Trust Center
  • Status

Social

  • GitHub
  • X
  • LinkedIn
  • YouTube
  • Instagram
  • VercelVercel
Agent Stack
  • AI SDK
  • AI Gateway
  • Sandbox
  • Workflows
  • Passport
  • eve
Core Platform
  • Security
  • Content Delivery
  • Fluid Compute
  • Observability
  • CI/CD
Tools
  • Next.js
  • Vercel Agent
  • Vercel Plugin
  • Domainsโ†—
  • v0โ†—
Learn
  • Docs
  • About
  • Blog
  • Changelog
  • Knowledge Base
Build
  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce
Explore
  • Customers
  • Marketplace
  • Partner Finder
  • AWS
  • Communityโ†—
EnterprisePricing
Contact
Log InSign Up
Dashboard

Products

Agent Stack

  • AI SDK
  • AI Gateway
  • Sandbox
  • Workflows
  • Passport
  • eve

Core Platform

  • Security
  • Content Delivery
  • Fluid Compute
  • Observability
  • CI/CD

Tools

  • Next.js
  • Vercel Agent
  • Vercel Plugin
  • Domainsโ†—
  • v0โ†—
Resources

Learn

  • Docs
  • About
  • Blog
  • Changelog
  • Knowledge Base

Build

  • AI Apps
  • Web Apps
  • Marketing Sites
  • Platforms
  • Commerce

Explore

  • Customers
  • Marketplace
  • Partner Finder
  • AWS
  • Communityโ†—
Enterprise
Pricing
Sign UpLog In
Contact
DeployView Demo

Loading statusโ€ฆ

Select a display theme: