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.
app directory
..env.example
to .env
and fill in the required environment variables.pnpm install
to install dependencies.(for node v18 or lower):
Uncomment polyfills for webCrypto
in src/lib/auth/index.ts
src/lib/constants.ts
file.pnpm db:push
to push your schema to the database.pnpm dev
to start the development server and enjoy!pnpm exec playwright install chromium --with-deps
)pnpm build
pnpm test:e2e
(add --debug flag to open tests in browser in debug mode)Add the following environment variables to your github actions repository secrets -
DATABASE_URL
, DISCORD_CLIENT_ID
, DISCORD_CLIENT_SECRET
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.