Create T3 App + Lucia Authentication
Auth implementation for Nextjs is a pain. Specially Email+Password authentication. NextAuth intentionally limeted email password functionality to-
discourage use of passwords due to the inherent security risks associated with them and the additional complexity associated with supporting usernames and passwords.
But in some projects clients require user password authentication. Using 3rd party auth providers are costly. Here, lucia comes to the rescure. Lucia is a more flexible alternative to NextAuth.js. This template is a starting point for building a Next.js app with Lucia authentication.
Lucia is a server-side authentication library for TypeScript that aims to be unintrusive, straightforward, and flexible. At its core, it’s a library for managing users and sessions, providing the building blocks for setting up auth just how you want.
Lucia v/s NextAuth.js (Auth.js)
Lucia is less opinionated than Next Auth. NextAuth is too rigid if you want to customize it. Although lucia has more setup but with that comes so much more flexibility.
Key Features
- Auth: Signup/Login using credentials or OAuth and protected app and api routes with Lucia auth
- Email Verification: User verification using email.
- Password Reset: Reset user passwords by emailing password reset link.
- Lucia + Trpc: similar to NextAuth with tRpc,access session and user from trpc proceedures.
Tech Stack
Get Started
- Clone the repository
git clone https://github.com/iamtouha/next-lucia-auth.git
. - Copy
.env.example
to.env
and fill in the necessary environment variables. - Run
pnpm install
to install dependencies. - Update app title, database prefix and other parameters from
src/lib/constants.ts
file. - Run
pnpm db:push
to push your schema to database. pnpm dev
and enjoy!