Giter VIP home page Giter VIP logo

api-auth's Introduction

API with user registration, user authentication, and rate limiting

Core Packages

  1. Express - Web framework
  2. PostgreSQL - Database
  3. Sequelize - ORM
  4. JWT - Token generation and validation
  5. Express Rate Limit - Rate limiting
  6. Bcrypt - Password hashing
  7. Dotenv - Environment variables
  8. Nodemon - Development

Setup

  1. Clone the repository git clone
  2. Install dependencies npm install
  3. Create a .env file in the root directory and add the following environment variables: DATABASE_URL, PORT, JWT_SECRET, JWT_EXPIRE
  4. Run npm run dev to start the server in development mode
  5. Run npm start to start the server in production mode

API Endpoints

POST /api/auth/signup

  • Creates a new user
  • Request body:
    • username
    • email
    • password
    • secretImg
  • Response:
    • 200 OK on success
    • 400 Bad Request if username or email already exists
    • 500 Internal Server Error on server error
    • Response body:
      • success
      • data

POST /api/auth/login

  • Authenticates a user
  • Request body:
    • username
    • password
  • Response:
    • 200 OK on success
    • 400 Bad Request if username or password is incorrect
    • 500 Internal Server Error on server error
    • Response body:
      • success
      • data

- GET /api/secret

  • Returns a secret message
  • Request Headers:
    • authorization - Bearer token
  • Response:
    • 200 OK on success
    • 401 Unauthorized if token is invalid
    • 429 Too Many Requests if rate limit is exceeded
    • 500 Internal Server Error on server error
    • Response body:
      • success
      • data

Rate Limiting

  • Rate limiting is implemented using the Express Rate Limit package
  • The rate limit is set to 10 requests per minute
  • The rate limit is applied to the /api/secret endpoint

api-auth's People

Contributors

sanjai0py avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.