1.1.0 • Published 3 years ago

library.io-libs v1.1.0

Weekly downloads
7
License
ISC
Repository
github
Last release
3 years ago

Library.io-libs

An implementation of JSON Web Tokens.

Initialize

const LibraryAuth = require("library.io-libs/dist/authorization")

const libraryAuth = new LibraryAuth(process.env.TOKEN_PRIVATE_KEY)
  • Define Library role enum
ADMIN
CLIENT
AUTHOR 
FunctionExplain
generateTokenGenerate token with the private key
decodeTokenGet jwt token fields (middleware)
verifyPermissionVerify token has correct role (middleware)
equalFieldVerify token has correct Field value* (middleware)

Examples

router.put("/:id", [decodeToken], (async (req, res) => {

router.put("/:id", [verifyToken], (async (req, res) => {

router.put("/:id", [verifyPermission(LibraryRoles.ADMIN)], (async (req, res) => {

# Only the user with this ID can update his row 
router.put("/:id", [equalField("id")], (async (req, res) => {
1.1.0

3 years ago

1.0.10

3 years ago

1.0.5

3 years ago

1.0.0

3 years ago