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
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.
Lastly, make sure you have the following installed.
- Latest version of Node.js
- Latest version of NPM (Node Package Manage)
- Latest version of MongoDB
- Latest version of git (This is optional. It requires only if you choose to clone project)
-
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
-
-
Navigate to project directory in the terminal or command prompt.
cd mern-jwt-auth
-
Install project dependencies
npm i && npm run client-install
-
Create a
keys.js
file inconfig
directory-
If you are using Windows
Command Promtp
orPowershell
copy config/keys.sample.js config/keys.js
-
If you using
Mac
orLinux
cp config/keys.sample.js config/keys.js
Note: update
keys.js
file variables as per the requirements. -
-
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
-
-
-
Project server is running at:
-
Development
- Frontend server is running at http://localhost:3000
- Backend server is running at http://localhost:5000
-
Production server is running at http://localhost:5000
-
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
-
Register
-
Endpoint -
/api/users/register
-
HTTP Method - POST
-
Payload
{ "name": "Vishal", "email": "[email protected]", "password": "test123", "password2": "test123" }
-
-
Login
-
Endpoint -
/api/users/login
-
HTTP Method -
POST
-
Payload
{ "email": "[email protected]", "password": "test123" }
-
- Fork it ( https://github.com/vishalnagda1/mern-jwt-auth/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new pull request.