The Mongo DB handler is a nodejs backend to provide user related APIs for broker.
- nodejs - v12.14.1
- npm - 6.14.8
Install all dependencies
npm install
Create a .env file based on envexample file. Four values are need in it:
-
MONGODB_ENDPOINT : which is the endpoint of your MongoDB
-
JWT_SECRET : which is a random string for token generation and verification (Shouldn't be exposed to others)
-
ADMIN_PASSWORD : an admin user (username:admin) will be created if there is no such user in Mongo DB and this is the password for admin (Shouldn't be exposed to others)
-
BROKER_URL : which defines the url of broker-core component
Run the application
npm start
MongoDB models. Use mongoose schema.
hash password and compare password are defined here using bcrypt.
/auth
-
POST
/
to authenticate user by checking username and password and return token and user -
GET
/user
to get the current user using valid token
/users
-
GET
/
to get all users in the database -
POST
/add
to add new user in database (admin only) -
POST
/update/:id
to update user in database (admin only) -
DELETE
/delete/:id
to delete user in database (admin only)
to check the token is valid or not
to check the role of the user is admin or not