It is a simple example of how to use Next-Auth with Next.js v4. I have used OAuth and Credentials provider for authentication. I hope you will find it useful. ๐
I will try to add email provider for magicLink authentication. in the nearest future.
Manually download the code or clone it from the repository:
git clone
install all the dependencies:
npm install
Open code editor and create .env file with the following content:
NEXTAUTH_URL="Your domain link"
GOOGLE_CLIENT_ID="Your google client id"
GOOGLE_CLIENT_SECRET="Your google client secret"
MONGO_URI=mongodb:"Your mongo uri"
if you are using the app for testing/developement you can use
NEXTAUTH_URL=http://localhost:3000
MONGO_URI=mongodb://localhost:27017/DatabaseName
if you are using the app for production you can use
NEXTAUTH_URL=https://yourdomain.com
MONGO_URI=your cloud DB URI
Then, run the development server:
npm run dev
# or
yarn dev
Open http://localhost:3000 with your browser to see the result.
You can start editing the page by modifying pages/index.js
. The page auto-updates as you edit the file.
API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.js
.
The pages/api
directory is mapped to /api/*
. Files in this directory are treated as API routes instead of React pages.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.
Check out our Next.js deployment documentation for more details.