Flight booking API with Authentication using Bcrypt and JSON Web Tokens
Setting up the local server.
- Get a free MongoDB atlas account MongoDB Atlas
- Set up a free tier project and obtain connection URI that looks like so -
mongodb+srv://<USERNAME>:<PASSWORD>@auth-authorizationjwt.xsbmedo.mongodb.net/?retryWrites=true&w=majority
- Clone this repository, switch into this directory and run
yarn add
ornpm install
to install all required packages - Create .env file and add your
SECRET_KEY_<ROLE>
Routes definition
All routes are protected except for creating a user route and logging in to obtain the token
User
- The base route is
/user
- Create a user route
/register
. Method =POST
- Log-in user route
/login
. Method =POST
- Delete user route
/delete/<id>
. Method =DELETE
Admin
- The base route is
/admin
- Create an admin route
/register
. Method =POST
- Log-in admin route
/login
. Method =POST
- Delete admin route
/delete/<id>
. Method =DELETE
Flight endpoints
Users are able to:
- Book Flight
- Get all flights
- Get a single Flight
Admins are able to:
- Update Flights
- Delete Flights
- Add flights
Flights have the following attributes: { title: "flight to canada", time: 1pm, price: 26000, date: "26-06-2022" }