Hello all, This REST API is a simple way of handling authentication using JWT tokens. Keep reading for more details 👇. Cheers!
git clone https://github.com/emilsharier/jwt-auth
npm install
NOTE! If you're running the project in dev mode, make sure you create a .env file which would consist of the following
SECRET=<Some secret private key>
DATABASE_URL=<Database URL>
npm run dev
npm start
express (To handle all HTTP requets and responses)
jsonwebtoken (Middleware to validate and verify JWT tokens)
bcrypt (For enrypting and hashing the password using a private key)
morgan (Logging middleware)
sequelize (An ORM so that you can implement the database of your choice)
pg (In my case I decided to use PostgreSQL)
POST methods
- /signup
The request body should contain the following details. You can choose to pass them as x-www-form-urlencoded parameters.
- password
- name
- phone
The response can be either of the three status codes
- 200 - OK (Registration successful)
- 401 - Unrecognized error (Mostly database/internal error)
- 403 - Email already exists
- /signin
The request body should contain the following details. You can choose to pass them as x-www-form-urlencoded parameters.
- password
The response can be eithre of the three status codes
- 200 - OK (The response body would contain the access token that the client can store and later use to send requests)
- 403 - Error (When the user is not registered or when the access token isn't attached on the request header)
- 401 - Unauthorized (Wrong password)
All Pull requests and issues are welcome. If you feel something's wrong fork and issue a PR or just put up a new issue!
Cheers!