A modern authentication starter template for Next.js, featuring secure user management and a clean, extensible codebase. Built and maintained by SagarKarmoker.
This starter template comes in two versions to suit different database preferences:
mainbranch: MongoDB integration with Mongoose ODMprismabranch: PostgreSQL integration with Prisma ORM
You are currently viewing the [
mainbranch] — this is the MongoDB version.For the Prisma/PostgreSQL version, switch to the [
prismabranch].
- Next.js 13+ App Router: Leverages the latest Next.js features for performance and scalability.
- Authentication Kit: Modular authentication flow, ready for social and custom providers.
- MongoDB Integration: User data stored securely with Mongoose ODM.
- API Route Structure: Organized API endpoints for authentication and webhooks.
- Dashboard Example: Protected dashboard page for authenticated users.
- Reusable Components: Includes a customizable Navbar and global styles.
- TypeScript: Full type safety across the stack.
- ESLint & Prettier: Code quality and formatting enforced out of the box.
nextjs-authkit-starter/
├── app/ # Next.js app directory (pages, API routes)
│ ├── api/ # API endpoints (e.g., webhooks)
│ ├── auth/ # Authentication pages and callbacks
│ └── dashboard/ # Example protected dashboard
├── components/ # Reusable React components
├── lib/ # Utility libraries (e.g., Mongoose connection)
├── models/ # Mongoose models (User)
├── public/ # Static assets
├── middleware.ts # Auth middleware
├── next.config.ts # Next.js configuration
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
-
Clone the repository:
git clone https://github.com/SagarKarmoker/nextjs-authkit-starter.git cd nextjs-authkit-starter -
Install dependencies:
npm install
-
Configure environment variables:
- Copy
.env.exampleto.envand fill in your MongoDBMONGODB_URIand any authentication secrets. - For Prisma/PostgreSQL version, use
DATABASE_URLinstead ofMONGODB_URI.
- Copy
-
Run the development server:
npm run dev
Open http://localhost:3000 to view the app.
- Built-in authentication flow with extensible provider support.
- User data is securely stored in MongoDB via Mongoose ODM (this version).
- Example protected routes (e.g.,
/dashboard).
- Add new authentication providers in
app/auth/. - Extend the
Usermodel inmodels/User.model.ts(this version) orprisma/schema.prisma(Prisma version). - Customize UI components in
components/.
npm run dev– Start the development servernpm run build– Build for productionnpm run start– Start the production servernpm run lint– Run ESLint
Contributions are welcome! Please open issues or submit pull requests for improvements and bug fixes.
- Fork the repository
- Create your feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -m 'Add some feature') - Push to the branch (
git push origin feature/YourFeature) - Open a pull request
To switch between MongoDB and PostgreSQL versions:
-
For MongoDB version: Checkout the
mainbranchgit checkout main
-
For PostgreSQL version: Checkout the
prismabranchgit checkout prisma
This project is licensed under the MIT License.
Built with ❤️ by SagarKarmoker