This guide demonstrates how to integrate OAuth login using NextAuth.js, Resend for sending email verification links, and saving user data in PostgreSQL in a Next.js project.
demo.nextauth.mp4
- Next.js
- PostgreSQL Database
- NextAuth.js
- Resend for sending email verification code
- Prisma ORM for PostgreSQL
- Basic understanding of OAuth providers like Google and Github
-
Clone the project and install the dependecies
git clone https://github.com/Yash-946/Nextauth-Template.gitnpm i -
Setup the Environment variables, copy .env.example to .env
DATABASE_URL="" NEXTAUTH_SECRET="" GOOGLE_CLIENT_SECRET="" GOOGLE_CLIENT_ID="" GITHUB_CLIENT_ID="" GITHUB_CLIENT_SECRET="" RESEND_API_KEY="" -
Get the database connection url from Neon and than these commands to migrate the database and generate the prisma client
npx prisma migrate deploy npx prisma generate -
You can change the
NEXTAUTH_SECRETas per your need -
For
RESEND_API_KEYmake sure you have a domain and it is verify by Resend , only than you can send emails to anyone.
-
For setting up Google and Github secrets here is the demo 👇. Doc
demosetup.mp4
- Final run
npm run dev