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 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.
- 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.
- Stripe Payment: π³ Setup user subscriptions seamlessly with stripe.
- Email template with react-email: βοΈ Craft your email templates using React.
- MySQL Database: π’οΈ Utilize a MySQL database (Planetscale) 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.
- Next.js
- Lucia
- tRPC
- Drizzle ORM
- Planetscale
- Stripe
- Tailwind CSS
- Shadcn UI
- React Hook Form
- React Email
- Clone this repository to your local machine.
- Copy
.env.example
to.env
and fill in the required environment variables. - Run
pnpm install
to install dependencies. (for node v18 or lower):
Uncomment polyfills forwebCrypto
insrc/lib/auth/index.ts
- Update app title, database prefix, and other parameters in the
src/lib/constants.ts
file. - Run
pnpm db:push
to push your schema to the database. - Execute
pnpm dev
to start the development server and enjoy!
- Update Password
- Stripe Integration
- API Rate-Limiting see branch - upstash-ratelimiting
- Admin Dashboard (under consideration)
- Role-Based Access Policy (under consideration)
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.