Uma API REST de cadastro de usuário com autenticação em dois fatores via email.
Eu gravei um vídeo iniciando a aplicação e mostrando todos os endpoints funcionando, você poderá assistir ele aqui.
Utilizei o MailCatcher para o recebimento de emails, basta acessar http://127.0.0.1:1080/.
- node >= 21.6.0
- npm >= 10.2.4
- docker >= 24.0.7
- docker-compose >= 1.29.2
Intale o projeto e inicie com NPM or Yarn.
Você irá precisar renomear o arquivo .env.sample
para .env
git clone https://github.com/marcuuscardoso/challenge-backend
cd challenge-backend
yarn
docker-compose up -d
yarn dev
or
git clone https://github.com/marcuuscardoso/challenge-backend
cd challenge-backend
npm install
docker-compose up -d
npm run dev
Todos os endpoints da aplicação foram documentados utilizado Postman, você pode acessar a coleção do postman aqui.
Create OTP Code
POST /auth
Host: localhost:3000
Content-Type: application/json
Body
{
"email": "marcus@example.com",
"password": "testpassword"
}
Response:
{
"message": string
}
Create Access Token (With OTP Code)
POST /auth
Host: localhost:3000
Content-Type: application/json
Body
{
"email": "marcus@example.com",
"password": "testpassword",
"otpCode": "0123456"
}
Response:
{
"access_token": string
}
Get all users
GET /users
Host: localhost:3000
Authorization: Bearer access_token
Response:
[
{
"id": number,
"name": string,
"email": string,
"phone": string,
"password": string,
"createdAt": Date,
"updatedAt": Date
},
...
]
Get Single User
GET /users/<userid>
Host: localhost:3000
Authorization: Bearer access_token
Response:
{
"id": number,
"name": string,
"email": string,
"phone": string,
"password": string,
"createdAt": Date,
"updatedAt": Date
}
Create User
POST /users/
Host: localhost:3000
Content-Type: application/json
Body
{
"name": string,
"email": string,
"phone": string,
"password": string
}
Update User
PATCH /users/<userid>
Host: localhost:3000
Content-Type: application/json
Authorization: Bearer access_token
Body: something you want to update, by example:
{
"email": string
}
Delete User
DELETE /users/<userid>
Host: localhost:3000
Authorization: Bearer access_token