Full authentication backend application, using Node.js, express, docker, Postgres and Typescript. Developed using SOLID principles and good coding practices. Tests for all features and routes using Jest and Supertest.
Features:
- User registration
- Authentication
- Show user profile data.
- User data update.
- Upload a user profile picture.
- Send email for password recovery.
- Reset Password
- Node.js
- Express
- Multer
- TypeScript
- TypeORM
- PostgreSQL
- JWT-token
- uuid v4
- Date-fns
- Jest
- nodemailer
- tsyringe
- handlebars
Before downloading and running the project, you must have Node.js already installed and then install the following tools:
Open the terminal and execute the following commands:
# Clone the project
$ git clone https://github.com/marchetti2/auth-api.git
# Access the folder
$ cd auth-api
# Install the dependencies
$ yarn
Using the docker, start an instance of the databases below.
# PostgreSQL
$ docker run --name postgres -e POSTGRES_DB=auth-api -e POSTGRES_PASSWORD=docker -p 5432:5432 -d postgres
To find out if the databases are running, run the following command:
$ docker ps
If not, run:
$ docker start postgres
Run the following command:
$ yarn test
First, verify that the databases are running. From the API directory, run the following commands:
# Create tables in PostgreSQL
$ yarn typeorm migration:run
# Run the server
$ yarn dev:server
- To view the tables created in the postgres database, use DBeaver.
- To test the routes, you can use Insomnia. The workspace used in this API is available, just click the button below.
-
POST /users
: Register a new user. Send thefirst_name, last_name, email, password
body params. -
PATCH /users/avatar
: Update the user's avatar. Fill the bearer token with the token received from the authentication response. Configure the 'Multipart Form' type request with the name of the avatar field and upload the image file.
POST /sessions
: User authentication. Send theemail, password
body params.
-
GET /profile
: Show user profile (Only athententicated users can see). Fill the bearer token with the token received from the authentication response. -
PUT /profile
: Update profile. Fillfirst_name, last_name, password, email
body params and Bearer token received from authenticate response.
-
POST /password/forgot
: Password recovery. Fillemail
body params. -
POST /password/reset
: Change Password. Fillpassword, password_confirmation, token
body params. You will receive a link in the forgot request response to a fake email. The token is in the route params of the link sent in the fake email
This project was developed by Mário Luiz.