This project demonstrates the implementation of authentication using NextAuth.js with multiple providers, including Google, GitHub, Facebook, Twitter, and MongoDB. Users can log in using any of these providers or directly with MongoDB.
- Google Authentication
- GitHub Authentication
- Facebook Authentication
- Twitter Authentication
- MongoDB Authentication
Before running this project, ensure you have the following:
- Node.js installed
- MongoDB database set up
- API keys for Google, GitHub, Facebook, and Twitter
-
Clone the repository:
git clone .............. cd next-auth
-
Install dependencies:
npm install
-
Create a
.env.local
file in the root directory and add the following environment variables:NEXTAUTH_URL=http://localhost:3000 # Google GOOGLE_CLIENT_ID=your-google-client-id GOOGLE_CLIENT_SECRET=your-google-client-secret # GitHub GITHUB_CLIENT_ID=your-github-client-id GITHUB_CLIENT_SECRET=your-github-client-secret # Facebook FACEBOOK_CLIENT_ID=your-facebook-client-id FACEBOOK_CLIENT_SECRET=your-facebook-client-secret # Twitter TWITTER_CLIENT_ID=your-twitter-client-id TWITTER_CLIENT_SECRET=your-twitter-client-secret # MongoDB MONGODB_URI=your-mongodb-connection-string
-
Run the development server:
npm run dev
-
Open http://localhost:3000 in your browser.
- Navigate to the login page.
- Choose a provider (Google, GitHub, Facebook, Twitter) or log in using MongoDB credentials.
- Upon successful login, you will be redirected to the dashboard.
- Next.js
- NextAuth.js
- MongoDB
- OAuth Providers (Google, GitHub, Facebook, Twitter)
- Google : https://console.cloud.google.com/apis/credentials?pli=1&project=next-auth-login-446517
- Github : https://github.com/settings/applications/2928871
- Facebook : https://developers.facebook.com/
- Twitter : https://developer.twitter.com/en/portal/projects/1902771264332439552/apps/30425725/settings
- MongoDB : https://authjs.dev/getting-started/adapters/mongodb