Skip to content

Minimal full-stack MERN app with authentication using passport and JWTs.

License

Notifications You must be signed in to change notification settings

vishalnagda1/mern-jwt-auth

Repository files navigation

MERN JWT Auth

GitHub license Repository version

MERN JWT Auth is a minimal full-stack login/authorization app developed using the MERN stack (MongoDB for our database, Express and Node for our backend, and React for our frontend). Also integrate Redux for state management for our React components.

MERN JWT Auth app will allow users to

  • Register
  • Log in
  • Access protected pages only accessible to logged in users
  • Stay logged in when they close the app or refresh the page
  • Log out

Requirements

Prerequisites

You should have at least a basic understanding of fundamental programming concepts and some experience with introductory HTML/CSS/Javascript. And the knowledge of MERN stack (Mongo, Express, React, Node) is an advantage.

Install

Lastly, make sure you have the following installed.

Getting Started

  1. Either you can clone or download repository from GitHub.

    • Clone with HTTPS (required git installed in your system)

      git clone https://github.com/vishalnagda1/mern-jwt-auth.git
    • Clone with SSH (required git installed in your system)

      git clone [email protected]:vishalnagda1/mern-jwt-auth.git
    • Download Zip

  2. Navigate to project directory in the terminal or command prompt.

    cd mern-jwt-auth
  3. Install project dependencies

    npm i && npm run client-install
  4. Create a keys.js file in config directory

    • If you are using Windows Command Promtp or Powershell

      copy config/keys.sample.js config/keys.js
    • If you using Mac or Linux

      cp config/keys.sample.js config/keys.js

    Note: update keys.js file variables as per the requirements.

  5. Run the project server

    • Run development server (it runs both frontend and backend server together at same time)

      npm run dev
    • Run backend development server

      npm run server
    • Run frontend development server

      npm run client
    • Run production server

      • Build and run the production server

        npm run build-prod

      OR

      • Create build first

        npm run build

        Run the production server

        npm run prod
  6. Project server is running at:

Note

You might get below give error while runnning client server checkout this issue for more information.

digital envelope routines::unsupported

Then you can execute below command before starting the server

export NODE_OPTIONS=--openssl-legacy-provider

Backend APIs

  1. Register

    • Endpoint - /api/users/register

    • HTTP Method - POST

    • Payload

      {
          "name": "Vishal",
          "email": "[email protected]",
          "password": "test123",
          "password2": "test123"
      }
  2. Login

    • Endpoint - /api/users/login

    • HTTP Method - POST

    • Payload

      {
      	"email": "[email protected]",
      	"password": "test123"
      }

Contributing

  1. Fork it ( https://github.com/vishalnagda1/mern-jwt-auth/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new pull request.