Basic demo to show the usage of the React context API with authentication flow
Project Structure:
-server
-src
-data
-schemas
-logic
-routes
-utils
-index.js
-.env
-client
-public
-src
-components
-pages
-providers
-services
-utils
-App.js
-index.js
-.env
System Requirements:
- Node
- Mongodb
Server:
- Install the project dependencies
$ npm i
- Create the .env file on the root of the server/ folder
$ touch .env
.env
DB_URL=mongodb://localhost:27017/your-database
PORT=5000
TOKEN_SECRET=your-secret
TOKEN_EXP=3h
- Start the Server
$ npm start
Client:
- Download dependencies
$ npm i
- Create the .env file on the root of the client/ folder
$ touch .env
.env
REACT_APP_API_BASE_URL=http://localhost:5000/api
*Note: In order to enviroment variables work with this react project without touching any config file they all have to start with **REACT_APP**
- Start the client
$ npm start
Author: http://github.com/mikelpmc