ywemay-api-user
v1.1.8
Published
API user functions
Downloads
4
Readme
API User
Provides authentication/authorization functions for a Mongo DB based user.
Setup
#install the module:
npm i ywemay-api-user
NOTE: This module requires a Mongoose connection to operate.
The .env
file should contain the following keys with appropriate values:
# a string used to encrypt the token:
JWT_KEY="replace this string with any random string for token encryption"
# how many tries to login are allowed until user is delayed (by IP)
LOGIN_MAX_TRIES=10
# how long time to wait (minutes) until log in is allowed again
LOGIN_DELAY=20
Usage example:
This is how user routes may be added to the application:
const express = require("express");
const db = require("./db");
const users = require("ywemay-api-user");
// initialize express application
const app = express();
app.use(express.json());
db.connect();
users.config(app);
module.exports = app;
Endpoints
POST /auth/login
GET /auth/logout
POST /avatar/upload
GET /img/avatar
GET /user/preferences
PUT /user/preferences
PUT /user/change-password
GET /users
GET /users/id/:uid
GET /ref
POST /users
PUT /users/id/:uid
PUT /users
DELETE /users/id:uid
DELETE /users