3.0.1 • Published 3 years ago
tenantapp-authentication v3.0.1
tenantapp-authentication
This package provides features to authenticate users and perform other authentication related procedure in tenantApp. it exports 3 functions namely:
- generateToken (obj)
- verifyToken ()
- extractDataFromToken ( dataToBeRecovered, token )
Installation
To install, use the command below
npm install tenantapp-authentication
Usage
Generate Token
const { generateToken } = require('tenantapp-authentication');
const token = generateToken({your payload});
Verify Token
const { verifyToken } = require('tenantapp-authentication');
Then use the verifyToken variable as a middleware in your routes e.g:
router.get('/get-user-by-username/:username', verifyToken, View.getUserByUsername);
Extract Data from a token
To extract one of the data you encoded using generateToken function, follow this steps:
const { extractDataFromToken } = require("tenantapp-authentication");
const data = extractDataFromToken('userId', token);
very easy, right? that's all you have to do.
NOTE:
You have to configure the token secret key before you can use this package; to do this, set TOKEN_SECRET_KEY variable in your .env file to a desired value