Skip to content

Latest commit

 

History

History
58 lines (41 loc) · 1.07 KB

README.MD

File metadata and controls

58 lines (41 loc) · 1.07 KB

Setup

  1. Setup .env in the root
  2. Add MONGO_URI (MongoDB database URL)
  3. Add JWT_SECRET (key for the token)
  4. Add JWT_LIFETIME (token lifetime)
npm install && npm start

Swagger UI Docummentation

For more info go to: http://localhost:3000/api-docs/

Routers

  • auth.js
  • jobs.js

User Model

Email Validation Regex

/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

Register User

  • Validate - name, email, password - with Mongoose
  • Hash Password (with bcryptjs)
  • Save User
  • Generate Token
  • Send Response with Token

Login User

  • Validate - email, password - in controller
  • If email or password is missing, throw BadRequestError
  • Find User
  • Compare Passwords
  • If no user or password does not match, throw UnauthenticatedError
  • If correct, generate Token
  • Send Response with Token

Mongoose Errors

  • Validation Errors
  • Duplicate (Email)
  • Cast Error

Security

  • helmet
  • cors
  • xss-clean
  • express-rate-limit