Skip to content

Express JWT token authorization app created in educational purposes.

License

Notifications You must be signed in to change notification settings

1mpossible-code/jwt-authorization

Repository files navigation

JWT Authorization

Express jwt authorization app created in educational purposes. Only API.


Description

App that implements authorization with JWT token.

The front created on the base of API.

It uses bcryptjs to hash and verify passwords, eta to render pages, joi to validate data, jwt as an authorization token and mongoDB (mongoose) as a database.

Installation

Dependencies:

# Clone repo
git clone https://github.com/1mpossible-code/jwt-authorization
# Cd in it
cd jwt-authorization
# Install packages
npm install
# Copy .env.example and edit it optionally
cp .env.example .env
# Compose up
docker-compose up

You will have server on http://localhost:3000/

Usage

All routes described here:

Method Route Params Description
GET /register Render register page
POST /register {name: String, email: String, password: String} Register new user. Then show new created user's id
GET /login Render login page
POST /login {email: String, password: String} Login user. It will create cookie JWT token. Then redirect to test page
GET /logout Logout user. Delete token from cookie
GET /auth/me Get user's data in JSON format: {_id: String, name: String, email: String}
GET /test Test token if token is invalid or no token at all, else you will see the information of current user
GET /test/routes Render all routes page
GET / Redirect to '/test/routes'

Contributing

Feel freely to contribute this project. Issues and PRs are welcome!

Credits

You can mail to [email protected] to contact the author

License

Copyright © 2021 1mpossible-code. This project is GPLv3 licensed.