https://github.com/sabo99/nodejs-restfulapi-jwt-mongob
NodeJS-Express | Restful API with MongoDB : User Authentication, Authentication JWT (Json Web Token) & Device Detector User Login
https://github.com/sabo99/nodejs-restfulapi-jwt-mongob
api bcryptjs device-detector dotenv express joi-validation jsonwebtoken jwt mongodb mongoose nodemon rest rest-api restful-api
Last synced: 2 months ago
JSON representation
NodeJS-Express | Restful API with MongoDB : User Authentication, Authentication JWT (Json Web Token) & Device Detector User Login
- Host: GitHub
- URL: https://github.com/sabo99/nodejs-restfulapi-jwt-mongob
- Owner: sabo99
- Created: 2021-11-15T15:16:40.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-05-05T13:47:46.000Z (about 4 years ago)
- Last Synced: 2025-01-14T15:20:22.157Z (over 1 year ago)
- Topics: api, bcryptjs, device-detector, dotenv, express, joi-validation, jsonwebtoken, jwt, mongodb, mongoose, nodemon, rest, rest-api, restful-api
- Language: JavaScript
- Homepage:
- Size: 176 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Restful API with MongoDB : User Authentication + CRUD, Authentication JWT (Json Web Token) & Device Detector User Login
## Technology Used
- `bcryptjs: ^2.4.3`
- `device-detector-js: ^3.0.0`
- `cors: ^2.8.5`
- `dotenv: ^10.0.0`
- `express: ^4.17.1`
- `joi: ^17.4.2`
- `jsonwebtoken: ^8.5.1`
- `mongoose: ^6.0.12`
- `nodemon: ^2.0.15`
## Project Structure

## APIs Provided
| Methods | Urls | Actions | Token |
| :---------- | :-------------------- | :-------------------------: | :--------: |
| GET | / | Retrieve Base on APIs | - |
| POST | /api/auth/signup | SignUp new Account | - |
| POST | /api/auth/signin | Login an Account | - |
| GET | /api/user/public | Retrieve Public Content | - |
| GET | /api/user/list | Retrieve Users List Content | `Required` |
| GET | /api/user/find | Retrieve User Content | `Required` |
| PUT / PATCH | /api/user/{id}/update | Update User Content | `Required` |
| DELETE | /api/user/{id}/delete | Delete User Content | `Required` |
## Flow for SignUp & SignIn with JWT Authentication
Following diagram shows the flow that we will implement for the `User Registration`, `User Login`, and `Authenticate JWT` Processes.

## APIs Specification
## `Base APIs`
Request :
- Method : `GET`
- Endpoint : `/`
- Header :
- Content-Type : `application/json`
- Accept : `application/json`
- Response :
```json
{
"code": "number",
"message": "string"
}
```
## `User Registration`
Request :
- Method : `POST`
- Endpoint : `/api/auth/signup`
- Header :
- Content-Type : `application/json`
- Accept : `application/json`
- Body :
```json
{
"email": "string",
"username": "string",
"password": "string, hash"
}
```
- Response :
```json
{
"code": "number",
"message": "string",
"user": {
"_id": "string",
"email": "string",
"username": "string",
"createdAt": "date-string"
}
}
```
## `User Login`
Request :
- Method : `POST`
- Endpoint : `/api/auth/signin`
- Header :
- Content-Type : `application/json`
- Accept : `application/json`
- Body :
```json
{
"username": "string",
"password": "string, hash"
}
```
- Response :
```json
{
"code": "number",
"message": "string",
"user": {
"_id": "string",
"email": "string",
"username": "string",
"createdAt": "date-string"
},
"device-info": {
"client": "object",
"os": "object",
"device": "object",
"bot": "object"
}
}
```
## `Public Content`
Request :
- Method : `GET`
- Endpoint : `/api/user/public`
- Header :
- Content-Type : `application/json`
- Accept : `application/json`
- Response :
```json
{
"code": "number",
"message": "string"
}
```
## `User List`
#### `Require token`
Request :
- Method : `GET`
- Endpoint : `/api/user/list`
- Header :
- Content-Type : `application/json`
- Accept : `application/json`
- x-auth-token : `string`
- Response :
```json
{
"code": "number",
"message": "string",
"user": [
{
"_id": "string",
"email": "string",
"username": "string",
"createdAt": "date-string"
},
{
"_id": "string",
"email": "string",
"username": "string",
"createdAt": "date-string"
}
]
}
```
## `Find User`
#### `Require token`
#### example: `/api/user/find?id=1`
Request :
- Method : `GET`
- Endpoint : `/api/user/find`
- Query :
- id : `string`
- Header :
- Content-Type : `application/json`
- Accept : `application/json`
- x-auth-token : `string`
- Response :
```json
{
"code": "number",
"message": "string",
"user": {
"_id": "string",
"email": "string",
"username": "string",
"createdAt": "date-string"
}
}
```
## `Update User`
#### `Require token`
Request :
- Method : `PUT / PATCH`
- Endpoint : `/api/user/{id}/update`
- Header :
- Content-Type : `application/json`
- Accept : `application/json`
- x-auth-token : `string`
- Body :
```json
{
"email": "string",
"username": "string",
"password": "string, hash"
}
```
- Response :
```json
{
"code": "number",
"message": "string"
}
```
## `Delete User`
#### `Require token`
Request :
- Method : `DELETE`
- Endpoint : `/api/user/{id}/delete`
- Header :
- Content-Type : `application/json`
- Accept : `application/json`
- x-auth-token : `string`
- Response :
```json
{
"code": "number",
"message": "string"
}
```