Caution
The maintainer of the Lucia authentication library has announced plans to deprecate it early next year. Due to the library's limitations and complexity, particularly around database adapters, the maintainer has decided to shift focus to providing Lucia as an open-source resource for learning how to implement authentication and sessions from scratch. This new direction will include tutorials and examples for advanced features like 2FA, password reset, and rate limiting, while the Discord server will continue to offer general auth support. The current version of Lucia (v3) will be maintained for another six months (early 2025), with some adapters possibly deprecated sooner. lucia-auth discussions #1707
Tip
Use this New Template with Better Auth instead of Lucia Auth.
Welcome to the Next.js Drizzle MySQL Tailwind Lucia Template! This template offers a comprehensive starting point for building web applications using cutting-edge technologies like Next.js, Drizzle ORM, MySQL, Tailwind CSS, @tanstack/react-query, and Lucia.
- Live Demo
- Database Hosting
- Installation
- Usage
- Project Structure
- Dependencies
- Development Dependencies
- Best Practices
- Docker Setup
- License
Experience the live demo of this template deployed on Vercel: Next.js Drizzle MySQL Tailwind Demo.
For the database, this template uses MySQL. You can configure any database you want. Refer to the Drizzle Documentation for more details.
Get up and running quickly by following these steps:
Ensure you have the following installed:
Start by cloning the repository to your local machine:
git clone https://github.com/Its-Satyajit/nextjs-drizzle-mysql-tailwind.git
Move into the project directory:
cd nextjs-drizzle-mysql-tailwind
Install the necessary dependencies using your preferred package manager:
- Using npm:
npm install
- Using pnpm:
pnpm install
- Using yarn:
yarn install
- Using bun:
bun install
Configure your database by adding credentials to the .env
file. Then, generate and migrate your database schema:
- Using npm:
npm run dk:gen npm run dk:mig
- Using pnpm:
pnpm run dk:gen pnpm run dk:mig
- Using yarn:
yarn run dk:gen yarn run dk:mig
- Using bun:
bun run dk:gen bun run dk:mig
Once everything is set up, start the development server:
- Using npm:
npm run dev
- Using pnpm:
pnpm run dev
- Using yarn:
yarn run dev
- Using bun:
bun run dev
Note: If you're using Bun and encounter any issues, please refer to Bun's documentation as some commands may differ.
This template includes a set of scripts to streamline your development process:
dev-t
: Start the development server with the Next.js Turbopack bundler.dev
: Start the development server.build
: Build the application for production.start
: Start the application in production mode.lint
: Run ESLint for code linting.dk:gen
: Generate Drizzle ORM files for MySQL.dk:push
: Push changes to the MySQL database using Drizzle ORM.dk:pull
: Introspect the MySQL database using Drizzle ORM.dk:stdio
: Launch Drizzle Kit Studio with verbose output.dk:mig
: Run database migrations.dk:introspect
: Introspect the database schema.
These scripts cover essential tasks during development and deployment.
The project's structure is thoughtfully organized to support efficient development:
root ├───drizzle │ └───meta ├───node_modules ├───public └───src ├───actions ├───app │ └───(auth) │ ├───signin │ └───signup ├───auth ├───components │ └───forms └───db └───schema
Feel free to adapt the project structure to meet the specific needs of your application.
This template leverages a robust set of dependencies to deliver high performance and scalability:
- @lucia-auth/adapter-drizzle: Integration of Lucia authentication with Drizzle ORM.
- @tanstack/react-query: Powerful data-fetching library for React.
- bcrypt: Secure password hashing library.
- drizzle-orm: A powerful ORM for MySQL.
- lucia: A lightweight JavaScript authentication library.
- mysql2: MySQL client for Node.js.
- next: The React framework for building server-rendered applications.
- oslo: Utility library for Node.js.
- react: A library for building user interfaces.
- react-dom: DOM-specific methods for React.
- zod: A TypeScript-first schema declaration and validation library.
- zustand: A small, fast, and scalable state-management library.
For a smooth development experience, the following tools and libraries are included:
- @tanstack/react-query-devtools: Devtools for @tanstack/react-query.
- @types/bcrypt: TypeScript definitions for bcrypt.
- @types/node: TypeScript definitions for Node.js.
- @types/react: TypeScript definitions for React.
- @types/react-dom: TypeScript definitions for React DOM.
- @typescript-eslint/eslint-plugin: TypeScript linting plugin for ESLint.
- @typescript-eslint/parser: TypeScript parser for ESLint.
- autoprefixer: PostCSS plugin to add vendor prefixes.
- drizzle-kit: CLI toolkit for Drizzle ORM.
- eslint: Linter for JavaScript and TypeScript code.
- eslint-config-next: ESLint configuration for Next.js projects.
- eslint-config-prettier: Ensures Prettier and ESLint play nicely together.
- eslint-plugin-drizzle: ESLint plugin for Drizzle ORM.
- postcss: Tool for transforming CSS with plugins.
- tailwindcss: Utility-first CSS framework for custom designs.
- typescript: A typed superset of JavaScript that compiles to plain JavaScript.
- Optimize Builds: Use Next.js Turbopack bundler (
npm run dev-t
) for faster builds during development. - State Management: Leverage
zustand
for scalable and efficient state management. - Code Quality: Use ESLint and Prettier for consistent code formatting and linting.
- Vercel Deployment: Deploy your application seamlessly on Vercel. Refer to the Next.js Deployment Documentation for detailed instructions.
- Docker: If you are interested in setting up a robust Docker environment for your project, check out my other repository, Docker Containers, which includes Docker stacks for:
- MySQL, MariaDB & phpMyAdmin Setup
- Portainer Setup
- PostgreSQL Setup
- Prometheus & Grafana Monitoring Stack
This project is licensed under the MIT License. For more details, please refer to the LICENSE file.