Skip to content

dadwic/next-auth-mongodb

Repository files navigation

NextAuth Credentials using MongoDB and Material UI

This is a NextAuth project with MongoDB and Material UI.

Configuration

Set up a MongoDB database

Set up a MongoDB database either locally or with MongoDB Atlas for free.

Set up environment variables

Copy the env.local.example file in this directory to .env.local (which will be ignored by Git):

cp .env.local.example .env.local

Set each variable on .env.local:

  • MONGODB_URI - Your MongoDB connection string. If you are using MongoDB Atlas you can find this by clicking the "Connect" button for your cluster.
  • NEXTAUTH_SECRET - Used to encrypt the NextAuth.js JWT, and to hash email verification tokens. This is the default value for the secret option in NextAuth and Middleware.

Run Next.js in development mode

npm install
npm run dev

# or

yarn install
yarn dev

Your app should be up and running on http://localhost:3000! If it doesn't work, create an issue GitHub Issues.

You will either see a message stating "You are connected to MongoDB" or "You are NOT connected to MongoDB". Ensure that you have provided the correct MONGODB_URI environment variable.

When you are successfully connected, you can refer to the MongoDB Node.js Driver docs for further instructions on how to query your database.

Open https://next-auth-mui.vercel.app with your browser to see the result.

About

NextAuth Credentials using MongoDB and Material UI

Resources

Stars

Watchers

Forks

Packages

No packages published