This is simple microservice for JWT Authentication with NodeJS & MongoDB.
git clone https://github.com/asepmaulanaismail/jwt-auth-nodejs-microservice
cd jwt-auth-nodejs-microservice/
node server.js
or
git clone https://github.com/asepmaulanaismail/jwt-auth-nodejs-microservice
cd jwt-auth-nodejs-microservice/
nodemon server.js
git clone https://github.com/asepmaulanaismail/jwt-auth-nodejs-microservice
cd jwt-auth-nodejs-microservice/
sudo docker build -t jwt-auth-nodejs:latest .
sudo docker run -d -p 8080:8080 jwt-auth-nodejs
Route to show a random message
GET: localhost:8080/
Response:
Hello! The API is at http://localhost:8080/api
Create a simple user
GET: localhost:8080/setup
Response:
{
"success": true
}
Route to authenticate a user
POST: localhost:8080/api/authenticate
Params:
{
"username": "asepmaulanaismail",
"password": "asep123!!",
"deviceId": "1"
}
Response:
{
"success": true,
"message": "Enjoy your token!",
"token": "<YOUR TOKEN HERE>"
}
Route to show a random message
GET: localhost:8080/api
Params:
{
"token": "<YOUR TOKEN HERE>",
"deviceId": "1",
"username": "asepmaulanaismail"
}
Response:
{
"message": "Welcome to the coolest API on earth!"
}
Verify token
POST: localhost:8080/api/verify
Params:
{
"token": "<YOUR TOKEN HERE>",
"deviceId": "1",
"username": "asepmaulanaismail"
}
Response:
{
"success": true,
"message": ""
}
Route to return all users
GET: localhost:8080/api/users
Params:
{
"token": "<YOUR TOKEN HERE>",
"deviceId": "1",
"username": "asepmaulanaismail"
}
Response:
[
{
"_id": "5a5862d28c16852c84d79d78",
"username": "asepmaulanaismail",
"password": "asep123!!",
"admin": true,
"__v": 0
}
]
Logging out
POST: localhost:8080/api/logout
Params:
{
"token": "<YOUR TOKEN HERE>",
"deviceId": "1",
"username": "asepmaulanaismail"
}
Response:
{
"success": true,
"message": ""
}