Skip to content

Aplicação Back-end de autenticação completa, utilizando Node.js, Express, Docker, Postgres e Typescript. Desenvolvida utilizando os princípios do SOLID e boas práticas de codigo e testes.

Notifications You must be signed in to change notification settings

marchetti2/auth-api

Repository files navigation

auth-api

About

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

Summary

Technologies

Tools
REST API Client

Getting started

Before downloading and running the project, you must have Node.js already installed and then install the following tools:

Download

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

Environment

Database

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

Tests

Run the following command:

$ yarn test

Running the API

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
Tools
  • 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.

Run in Insomnia

Routes

/users
  • POST /users: Register a new user. Send the first_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.

/sessions
  • POST /sessions: User authentication. Send the email, password body params.
/profile
  • 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. Fill first_name, last_name, password, email body params and Bearer token received from authenticate response.

/password
  • POST /password/forgot: Password recovery. Fill email body params.

  • POST /password/reset: Change Password. Fill password, 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

License

This project was developed by Mário Luiz.

About

Aplicação Back-end de autenticação completa, utilizando Node.js, Express, Docker, Postgres e Typescript. Desenvolvida utilizando os princípios do SOLID e boas práticas de codigo e testes.

Topics

Resources

Stars

Watchers

Forks