使用 Lucia 实现凭证与 OAuth 认证,替代 NextAuth 的邮箱密码限制
nextjs-sessionauth-template — Next.js 启动器模板
作者 saasykits
基于 Next.js 的会话认证启动模板,集成 Lucia、tRPC、Drizzle ORM、PostgreSQL、Stripe 与 React Email,提供凭证与 OAuth 登录、邮箱验证、密码重置及受保护路由。
看看你的网站会是什么样
浏览真实页面截图,比较内容排版与手机效果。点击下方缩略图切换,放大查看整页细节。
全部页面与视图 2
截图用于了解视觉与布局,交互效果请以实际项目为准。
值得关注的模板亮点
从已有项目资料中,快速了解它的特点。
在 app 目录内管理公开与受保护路由
包含邮箱验证与密码重置邮件流程
通过 tRPC 过程访问会话与用户信息
集成 Stripe 用户订阅与 React Email 邮件模板
使用 Drizzle ORM 与 PostgreSQL,附带数据库迁移脚本
模板详细介绍
这是一个 Next.js 启动模板,核心目标是解决 Next.js 中邮箱加密码认证的实现问题。README 说明 NextAuth 有意限制邮箱密码功能以降低安全风险与复杂度,而该模板改用 Lucia 作为认证方案,提供更灵活的定制空间,适合需要用户密码认证的项目。
模板在 app 目录内管理公开与受保护路由,支持凭证登录和 OAuth 登录,并包含邮箱验证与密码重置流程。认证会话可通过 tRPC 过程访问,类似 NextAuth 与 tRPC 的配合方式。数据层使用 Drizzle ORM 连接 PostgreSQL,附带数据库迁移脚本以扩展 schema。支付方面已集成 Stripe 用于用户订阅,邮件模板使用 React Email 编写。测试使用 Playwright 进行端到端测试。
技术栈包括 Next.js、React、Lucia、tRPC、Drizzle ORM、PostgreSQL、Stripe、Tailwind CSS、Shadcn UI、React Hook Form、React Email 和 Playwright。路线图中更新密码、管理后台和基于角色的访问策略尚未完成,Stripe 集成已完成。
适合你的项目吗?
适用场景
- 需要邮箱加密码登录且希望自定义认证逻辑的 Next.js 项目
- 需要同时支持凭证登录与 OAuth 登录的 Web 应用
- 需要邮箱验证和密码重置流程的订阅制产品
- 希望用 tRPC 统一处理认证会话与业务接口的团队
适合人群
- 熟悉 Next.js、TypeScript 与 PostgreSQL 的开发者
- 需要可定制认证方案而非固定认证服务的项目
- 计划集成 Stripe 订阅与事务邮件的 SaaS 原型
- 希望以端到端测试覆盖认证流程的团队
上手与定制指南
结合仓库当前版本的说明,按下面的资料检查内容、配置与运行要求。
- 1
克隆仓库后复制 .env.example 为 .env 并填写所需环境变量
- 2
使用 pnpm install 安装依赖
- 3
Node v18 或更低版本需在 src/lib/auth/index.ts 中取消 webCrypto polyfill 的注释
- 4
在 src/lib/constants.ts 中更新应用标题、数据库前缀等参数
- 5
运行 pnpm db:push 推送 schema 到数据库,再用 pnpm dev 启动开发服务器
授权与来源资料
使用条件与限制
免费使用 · 保留许可声明本次收录的是公开仓库中采用 MIT 许可的免费版本;免费范围为该版本代码,不代表外部服务或第三方素材免费。
使用时需要遵守
- 允许免费使用、修改、商用和分发该版本代码。
- 分发代码副本或实质性部分时,保留原作者版权声明和完整 MIT 许可声明。
- 代码按现状提供;担保与责任限制以原许可证及适用法律为准。
额外费用与待核对事项
- 使用前必须配置环境变量(如数据库连接、OAuth 客户端凭据等),需自行准备 PostgreSQL 数据库及第三方服务账号。
- 在 GitHub Actions 中运行需配置 DATABASE_URL、DISCORD_CLIENT_ID、DISCORD_CLIENT_SECRET 等仓库密钥,即依赖外部数据库与 Discord OAuth 服务。
- Stripe 订阅功能依赖 Stripe 外部服务与账号,可能产生交易费用,需自行注册并配置密钥。
- 端到端测试需额外安装 Playwright 及其浏览器依赖,属于额外环境要求。
- 在 Node v18 或更低版本运行时需手动取消 webCrypto polyfill 注释,否则认证功能可能不可用。
- 演示图片、字体、图标及其他第三方素材需按各自许可核对,不能仅凭代码的 MIT 许可判断。
- 域名、托管、数据库、支付或 AI 等外部服务可能另外收费。
查看原文依据
Permission is hereby granted, free of charge
许可证原文
Copy `.env.example` to `.env` and fill in the required environment variables.
README 原文
Add the following environment variables to your **github actions repository secrets** - `DATABASE_URL`, `DISCORD_CLIENT_ID`, `DISCORD_CLIENT_SECRET`
README 原文
Setup user subscriptions seamlessly with stripe.
README 原文
Install [Playwright](https://playwright.dev/) (use this command if you want to install chromium only `pnpm exec playwright install chromium --with-deps`)
README 原文
https://github.com/saasykits/nextjs-sessionauth-template/blob/main/LICENSEhttps://github.com/saasykits/nextjs-sessionauth-template/blob/main/README.md`(for node v18 or lower):` Uncomment polyfills for `webCrypto` in `src/lib/auth/index.ts`
README 原文
DeepSeek 根据仓库许可证和 README 整理 ·2026-09-30。结果仅覆盖已读取资料,依赖、图片、字体及后续条款变更以各自原文为准。
项目核对记录与介绍依据
模板资料
- 来源平台
- GitHub
- 资料与维护参考分
- 资料较完整 · 90 / 100
- 技术栈
- Next.js · React
- 网站类型
- 启动器
这个分数如何计算
本站按许可资料(最高30分)、演示链接(12分)、预览图(10分)、Star数(15分)、记录的维护时间(15分)、描述完整度(8分)、功能记录(5分)和分类资料(5分)计算。它不是代码、安全或性能测试,也不是 Google 评分;有链接不代表已实测可用。
这个项目需要核对什么
- 记录的仓库更新时间
- 2025-01-23
- 截图检查日期
- 2026-09-30
已收录演示链接。请用你的内容与屏幕尺寸检查;有演示不代表表单、认证或支付已经可用。
目录记录的主要技术栈是 Next.js。请通过依赖清单和锁文件核对实际版本与托管要求。这些说明基于收录资料,不代表代码审计或部署实测。
查看具体选型方法 →介绍的制作与核对状态
介绍由 AI 辅助整理目录与仓库资料。仓库作者不等于这篇介绍的审核者。
已完成服务器许可规则与 AI 来源核对;未经过人工编辑审核。
查看当时使用的来源资料
SHA-256: 4e7f62b4b448c2b066234328426dd0abb6ef2521d41da9024e900df626ae6a04
2026-09-30T08:11:21.186Z
来源文件 / 仓库# 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](https://nextjs.org) - [Lucia](https://lucia-auth.com/) - [tRPC](https://trpc.io) - [Drizzle ORM](https://orm.drizzle.team/) - [PostgreSQL](https://www.postgresql.org/) - [Stripe](https://stripe.com/) - [Tailwind CSS](https://tailwindcss.com) - [Shadcn UI](https://ui.shadcn.com/) - [React Hook Form](https://www.react-hook-form.com/) - [React Email](https://react.email/) - [Playwright](https://playwright.dev/) ## 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](https://playwright.dev/) (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 - [x] Stripe Integration <!-- - [x] API Rate-Limiting see branch - [upstash-ratelimiting](https://github.com/iamtouha/next-lucia-auth/tree/upstash-ratelimiting) --> - [ ] 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.
看看同类模板
对比同技术栈与用途的模板,找到更适合的视觉与内容结构。

ai-website-cloner-template
Clone any website with one command using AI coding agents
Next.js · 启动器

Next.js SaaS Starter
Next.js SaaS Starter 是 Next.js 官方维护的 SaaS 起点模板,定位介于学习资源和可直接部署的脚手架之间。
Next.js · SaaS

Next.js Commerce
Next.js Commerce 是 Vercel 团队维护的电商启动模板,基于 Next.js App Router 构建,采用服务端渲染、React Server Components、Server Actions …
Next.js · 电商

Next-js-Boilerplate
Next-js-Boilerplate 是一个面向 Next.js 16、Tailwind CSS 4 和 TypeScript 的启动器,核心定位是开发者体验优先。
Next.js · 启动器

tailwind-nextjs-starter-blog
tailwind-nextjs-starter-blog 是一个面向个人技术博客的 Next.js 与 Tailwind CSS 启动模板,其 v2 版本基于 App Router 与 React Server Comp…
Next.js · 博客

next-forge
Production-grade Turborepo template for Next.js apps.
Next.js · 启动器
