Skip to content

rtewari056/mern-stack-authentication-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Logo with shadow

Ultimate MERN Stack Authentication Boilerplate for production use

πŸš€ Demo

This application is deployed on DigitalOcean. Please check it out πŸ˜„ here.

mern-stack-authentication-boilerplate

πŸ–₯️ Tech Stack

Frontend:

HTML5Β  CSS3Β  JavaScriptΒ  BootstrapΒ  ReactΒ  React RouterΒ 

Backend:

Node JSΒ  HTML5Β  JWTΒ 

Database:

MongoDBΒ 

Deployed On:

DigitalOcean

⚑️ Features

  • Protected routes with Higher Order Components
  • Login with forgot password feature.
  • JWT protected APIs
  • Passwords are encrypted.
  • Image upload with Cloudinary
  • Toast notifications for user actions.

πŸ“ Project structure

β”œβ”€β”€ client/
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   β”œβ”€β”€ favicon.ico
β”‚   β”‚   β”œβ”€β”€ index.html
β”‚   β”‚   β”œβ”€β”€ logo192.png
β”‚   β”‚   β”œβ”€β”€ logo512.png
β”‚   β”‚   β”œβ”€β”€ manifest.json
β”‚   β”‚   └── robots.txt
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ assets/
β”‚   β”‚   β”‚   β”œβ”€β”€ email.svg
β”‚   β”‚   β”‚   β”œβ”€β”€ green_check.svg.json
β”‚   β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   β”‚   β”œβ”€β”€ logo.png
β”‚   β”‚   β”‚   └── user.svg
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ NavigationBar/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ NavigationBar.jsx
β”‚   β”‚   β”‚   β”‚   └── NavigationBar.css
β”‚   β”‚   β”‚   β”œβ”€β”€ ProfileModal/
β”‚   β”‚   β”‚   β”‚   └── ProfileModal.jsx
β”‚   β”‚   β”‚   └── index.js
β”‚   β”‚   β”œβ”€β”€ context/
β”‚   β”‚   β”‚   └── AuthProvider.jsx
β”‚   β”‚   β”œβ”€β”€ Pages/
β”‚   β”‚   β”‚   β”œβ”€β”€ ForgotPasswordPage/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ForgotPasswordPage.css
β”‚   β”‚   β”‚   β”‚   └── ForgotPasswordPage.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ HomePage/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ HomePage.css
β”‚   β”‚   β”‚   β”‚   └── HomePage.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginPage/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ LoginPage.css
β”‚   β”‚   β”‚   β”‚   └── LoginPage.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ PasswordResetPage/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ PasswordResetPage.css
β”‚   β”‚   β”‚   β”‚   └── PasswordResetPage.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ RegisterPage/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ RegisterPage.css
β”‚   β”‚   β”‚   β”‚   └── RegisterPage.jsx
β”‚   β”‚   β”‚   └── index.js
β”‚   β”‚   β”œβ”€β”€ Utils/
β”‚   β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   β”‚   β”œβ”€β”€ notify.js
β”‚   β”‚   β”‚   └── PrivateRoutes.jsx
β”‚   β”‚   β”œβ”€β”€ App.css
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   └── index.js
β”‚   β”œβ”€β”€ .env.example
β”‚   β”œβ”€β”€ package-lock.json
β”‚   └── package.json
β”œβ”€β”€ config/
β”‚   └── db.js
β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ auth.js
β”‚   └── private.js
β”œβ”€β”€ middleware/
β”‚   β”œβ”€β”€ auth.js
β”‚   └── error.js
β”œβ”€β”€ models/
β”‚   └── User.js
β”œβ”€β”€ routes/
β”‚   β”œβ”€β”€ auth.js
β”‚   └── private.js
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ errorResponse.js
β”‚   └── sendEmail.js
β”œβ”€β”€ .env.example
β”œβ”€β”€ .gitignore
β”œβ”€β”€ LICENSE
β”œβ”€β”€ package-lock.json
β”œβ”€β”€ package.json
β”œβ”€β”€ README.md
└── server.js

πŸ“– Prerequisites

In order to run the project you need node>=16 and npm>=8 installed on your machine.

🚩 Getting Started

1. Clone the mern-stack-authentication-boilerplate repository:

git clone https://github.com/rtewari056/mern-stack-authentication-boilerplate.git

2. Navigate into repo:

cd mern-stack-authentication-boilerplate

3. Rename .env.example into .env and put all creadentials:

# In the root directory put your creadentials
APP_BASE_URL=http://localhost:3000
NODE_ENV=development
PORT=5000
MONGO_URI="YOUR_MONGO_CONNECTION_URL"
JWT_SECRET="YOUR_JWT_SECRET"
JWT_EXPIRE=24 # In hours
SMTP_HOST=<YOUR_SMTP_SERVER_HOST_NAME>
SMTP_PORT=587
SMTP_USER=<YOUR_SMTP_SERVER_USER_NAME>
SMTP_PASSWORD=<YOUR_SMTP_SERVER_PASSWORD>
EMAIL_FROM=<EMAIL_ADDRESS_OF_SENDER>

# Now go to client folder and put your cloudinary creadentials 
REACT_APP_CLOUDINARY_CLOUD_NAME=<YOUR_CLOUDINARY_CLOUD_NAME>
REACT_APP_CLOUDINARY_UPLOAD_PRESET=<YOUR_CLOUDINARY_UPLOAD_PRESET>

4. Install package dependencies:

npm install # Server dependencies
cd client
npm install # Client dependencies

4. Run project:

In the root directory, open two terminal sessions and run both commands separately:

npm run client
npm run server

5. Open your browser and go to http://localhost:3000

πŸ‘€ Developer

Rohit Tewari

πŸ“¬ Contact

If you want to contact me, you can reach me through below handles.

LinkedIn Gmail Twitter

πŸ“ƒ License

MERN Stack Authentication Boilerplate is licensed under the MIT License.

Show your support by 🌟 the project