A simple authentication template using NextAuth.js, Prisma, and MongoDB, with support for Google, GitHub, and Magic Link (Email) authentication.
- 🚀 Features
- 🛠️ Installation
- 🔑 Getting API Credentials
- 🚀 Running the Project
- 🛠️ Built With
- 📜 License
- ⭐ Show Some Love!
- ✅ NextAuth.js with multiple authentication providers
- ✅ Google OAuth, GitHub OAuth, and Resend email authentication
- ✅ Prisma ORM with MongoDB
- ✅ Secure session handling with JWT
- ✅ Fully customizable authentication logic
- ✅ Additionally has dark mode toggle
git clone https://github.com/subhadeeproy3902/nextauth-prisma-mongo-template.git
cd nextauth-prisma-mongo-template
npm install
# or
yarn install
Create a .env.local file in the root directory and add the following:
# Follow the README.md for more information on how to get the environment credentials
AUTH_SECRET= #Run `npx auth secret` in your terminal
AUTH_TRUST_HOST=
DATABASE_URL=
AUTH_GOOGLE_ID=
AUTH_GOOGLE_SECRET=
AUTH_RESEND_KEY=
GITHUB_ID=
GITHUB_SECRET=
Follow these steps to get Google Client ID and Secret:
- Go to the Google Cloud Console.
- Create a new project or select an existing one.
- Navigate to API & Services → Library, enable Google Identity Platform.
- Go to API & Services → Credentials, click Create Credentials → OAuth Client ID.
- Set application type as Web Application and enter the following redirect URL:
http://localhost:3000/api/auth/callback/google
- Get the Client ID and Secret, and add them to
.env.local
:
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
Follow these steps to get GitHub Client ID and Secret:
-
Go to GitHub Developer Settings.
-
Click New OAuth App, then set the following details:
- Application Name: Your project name
- Homepage URL:
http://localhost:3000
(or your production URL) - Authorization Callback URL:
http://localhost:3000/api/auth/callback
-
Click Register Application.
-
Once registered, you will get a Client ID.
-
Click Generate a new client secret and copy it.
-
Add these credentials to your
.env.local
file:
GITHUB_CLIENT_ID=your-github-client-id
GITHUB_CLIENT_SECRET=your-github-client-secret
- Go to Resend API key
- Create your api key
- Add these credentials to your
.env.local
file:
AUTH_RESEND_KEY==your-resend-api-key
- Goto
src > lib > auth.ts
and change the following accordingly if you have a Resend domain, like mvp-subha.me
Resend({
apiKey: process.env.AUTH_RESEND_KEY!,
// from: 'Acme <[email protected]>', // If you are using Resend and do not have a domain
from: "your-project-name <brand@your-domain>", // For personal domains
sendVerificationRequest, // For customised emails
}),
npm run dev
# or
yarn dev
The app will be live at http://localhost:3000
.
- Next.js – React framework for server-side rendering
- TypeScript - Strongly typed programming language that builds on JavaScript
- NextAuth.js – Authentication for Next.js applications
- Prisma – ORM for database management
- MongoDB – NoSQL database for scalable storage
- Resend – Email authentication provider
- TailwindCSS – Utility-first CSS framework for styling
This project is licensed under the MIT License – feel free to use and modify it as needed.
If you found this project helpful, consider giving it a star ⭐ on GitHub!
The primary contact for inquiries about the project is Subhadeep Roy. Feel free to reach out for any questions, suggestions, or issues related to the project. My Linkedin.
💙 Happy Coding! 🚀