Skip to content

Users_post

Luigi Minardi edited this page Mar 1, 2022 · 1 revision

Return to Users

Create new user

Create a new user on the database.

Endpoint: /

Creating one Admin

Request Body:
{
	"name": "Adult",
	"age": 20,
	"surname": "User",
	"nickname": "adult",
	"email": "adult@gmail.com",
	"password": "1234",
	"isAdmin": true
}
Response Body:
Response code: 201
{
	"msg": "Adult, welcome!"
}

Creating one Normal User

Request Body:
{
	"age": 7,
	"surname": "User",
	"name": "Underage",
	"email": "kid@gmail.com",
	"password": "1234",
	"nickname": "kid"
}
Response Body:
Response code: 201
{
	"msg": "Underage, welcome!"
}

Finding user by email

Searching a user on the database by its email.

Endpoint: /email

Request:

This endpoint need login.

If you're using postman or insomnia to check the API remember to put the token of the logged user on the header, as Authorization: Bearer <token>.

Request Body:
{
	"email": "adult@gmail.com"
}
Response Body:
Response code: 200
{
	"id": 1,
	"name": "Adult",
	"age": 20,
	"surname": "User",
	"email": "adult@gmail.com",
	"nickname": "adult",
	"password": "$2b$10$ehA1HQZhz4k6cls.7iUb4.fzCPbGiD37/CPtPmKPTNDejcuWuXNXq",
	"isAdmin": true,
	"createdAt": "2022-02-26T20:12:57.000Z",
	"updatedAt": "2022-02-26T20:14:11.000Z"
}

Login a user

Do the login of a user registered before on the api.

Endpoint: /login
Request Body:
{
	"email": "adult@gmail.com",
	"password": "1234"
}
Response Body:
Response code: 200
{
	"user": {
		"id": 1,
		"name": "Adult",
		"age": 20,
		"surname": "User",
		"email": "adult@gmail.com",
		"nickname": "adult",
		"password": "$2b$10$ehA1HQZhz4k6cls.7iUb4.fzCPbGiD37/CPtPmKPTNDejcuWuXNXq",
		"isAdmin": true,
		"createdAt": "2022-02-26T20:12:57.000Z",
		"updatedAt": "2022-02-26T20:14:11.000Z"
	},
	"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjp7ImlkIjoxLCJuYW1lIjoiSmFpciIsImFnZSI6MTksInN1cm5hbWUiOiJEYSBTaWx2YSIsImVtYWlsIjoiamF6YW9AZ21haWwuY29tIiwibmlja25hbWUiOiJKYXppciIsInBhc3N3b3JkIjoiJDJiJDEwJGVoQTFIUVpoejRrNmNscy43aVViNC5mekNQYkdpRDM3L0NQdFBtS1BUTkRlamN1V3VYTlhxIiwiaXNBZG1pbiI6dHJ1ZSwiY3JlYXRlZEF0IjoiMjAyMi0wMi0yNlQyMDoxMjo1Ny4wMDBaIiwidXBkYXRlZEF0IjoiMjAyMi0wMi0yNlQyMDoxNDoxMS4wMDBaIn0sImlhdCI6MTY0NTk3ODU1MSwiZXhwIjoxNjQ2MDY0OTUxfQ.gA1vouJPUbDWQYPRRKYwdQRoN4_-f0Adx1oVrVefJy0"
}