View Code? Open in Web Editor
NEW
api with user registration, user authentication and rate limiting
api-auth's Introduction
API with user registration, user authentication, and rate limiting
- Express - Web framework
- PostgreSQL - Database
- Sequelize - ORM
- JWT - Token generation and validation
- Express Rate Limit - Rate limiting
- Bcrypt - Password hashing
- Dotenv - Environment variables
- Nodemon - Development
- Clone the repository
git clone
- Install dependencies
npm install
- Create a
.env
file in the root directory and add the following environment variables: DATABASE_URL
, PORT
, JWT_SECRET
, JWT_EXPIRE
- Run
npm run dev
to start the server in development mode
- Run
npm start
to start the server in production mode
- 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:
- Authenticates a user
- Request body:
- Response:
200 OK
on success
400 Bad Request
if username or password is incorrect
500 Internal Server Error
on server error
- Response body:
- 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:
- 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
Watchers