Before you need install follow tools in your machine: Git, Node.js, Docker. Beyond is good to has an editor for to work with the code like VSCode
- 1. Overview
- 2. How To Run
- 3. Prisma Local Database
- 4. How to create a new branch
- 5. Software Architecture
- 6. Recommended Extensions
Welcome to the Authentication and Authorization API! This API allows you to signin making authentication and authorization, receiving a token and a session cookie. This README provides instructions on how to set up and use the API. On this application you can see concepts like SOLID, EventEmitter, DRY, LOGS.
Result:
# Clone this repository
$ git clone https://github.com/LucasJunio/authentication-authorization-jwt-inversify-express
# Acces the project folder in your terminal/cmd
$ cd authentication-authorization-jwt-inversify-express
# Copy base.env to .env
$ cp base.env .env
# Build the image docker
$ docker build -t auth .
# Build the container docker
$ docker run -p 3001:3001 auth
# The aplication going to open in port:3001 - access http://localhost:3001
Run the development server local with "yarn", "npm", "pnpm" or manager package your preference:
# Create .env file
$ cp base.env .env
# Install dependencies
$ yarn install
# Generate the TypeScript code associated with your database models
$ npx prisma generate
# Building migrations
$ npx prisma migrate dev
# Building mock data
$ npx prisma db seed
# Run the project
$ yarn start
The aplication going to open in port:3001 - access http://localhost:3001
You can login by sending a POST request to the /api/v1/login
endpoint. Here's an example using cURL:
curl -X POST \
-H "Content-Type: application/json" \
-d '{
{
"username": "user",
"password": "123456"
}
}' \
http://localhost:3001/api/v1/login
The response will be a token.
You can evaluate the private route by sending a GET request to the /api/v1/private-route
endpoint. Here's an example using cURL:
curl -X GET
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN_HERE" \
-H "Cookie: session=YOUR_COOKIE_HERE" \
http://localhost:3001/api/v1/private-route
The response will include the machine name and its health score.
POST /private-route
: Checks if isAuthenticatedAndAuthorized middleware is working by getting session token and cookie.POST /login
: Generate a token and ssesion.
You can see the local database Prisma Studio is up on http://localhost:5555.
# Running local database
$ npx prisma studio
Result:
Ever that's necessary to create a new branch feature, create by [main]branch, implement your development, merge this feature/branch to develop, when all it's ok, give a merge of this feature/branch to main[branch].
Let's go to follow the git flow patterns to create a new branch, to more info browse in link below to learn more how to implement in simple way.
Workflow gitflow: https://www.atlassian.com/br/git/tutorials/comparing-workflows/gitflow-workflow
# Example creating a new branch
$ git checkout -b feature/TASK-1
For commit your changes, you can follow the suggestion to use conventional commits [https://www.conventionalcommits.org/en/v1.0.0/] for to improve your commit descriptions and help the understand of the team. Exist a extension in vscode that can help you with this mission.
vscode extension id in .vscode/extensions.json:
"recommendations": ["vivaxy.vscode-conventional-commits"]
Main folder tree.
C:.
- src
- ├───constants
- ├───core
- ├───middleware
- ├───modules
- │ ├───controllers
- │ ├───dtos
- │ ├───inputs
- │ ├───interfaces
- │ ├───repositories
- │ ├───services
- │ └───validators
- └───util
You can check out a list of recommended extensions in the file .vscode/extensions.json
, or by opening the "Extensions" Tab in the "Recommended" pane.
Lucas Junio 🚀
Made with ❤️ by Lucas Junio 👋🏽 Contact