0.0.20 • Published 1 year ago
hgi-jwt v0.0.20
Authorization utility
You can use this module to generate JWT tokens and validate them
on NodeJS platform with an Express middleware automatically.
Create .env file in root project directory
Available configuration options:JWT_SECRET
=MySecretKeyJWT_EXPIRY_TIME
=60
This one only for development:JWT_NO_AUTH
=Yes
Installation
npm i hgi-jwt@latest
Sample usage 1
hgi_jwt = require('hgi-jwt')
var express = require('express')
app.use(express.cookieParser());
app.use(function (req, res, next) {
return res.cookie('jwt', hgi_jwt.generate())
}
// and then when needed before any use ()...
app.use(hgi_jwt.authorize())
Sample usage 2
hgi_jwt = require('hgi-jwt')
var express = require('express')
app.use(express.cookieParser());
hgi_jwt.generate({ role: 'admin', myData: 'something' })
// and then when needed before any use()...
app.use(hgi_jwt.authorize( role: 'admin' ))
// or with some exclusions...
app.use(hgi_jwt.authorize({
exclude: [
'/some/index.html',
'/some/api/.*' ]}))
// to retrieve payload from JWT do this...
app.use(function (req, res, next) {
let payload = hgi_jwt.payload(req)
}
0.0.20
1 year ago
0.0.18
3 years ago
0.0.19
3 years ago
0.0.17
3 years ago
0.0.15
3 years ago
0.0.16
3 years ago
0.0.14
3 years ago
0.0.13
3 years ago
0.0.12
3 years ago
0.0.11
3 years ago
0.0.10
3 years ago
0.0.9
3 years ago
0.0.8
3 years ago
0.0.7
3 years ago
0.0.6
3 years ago
0.0.5
3 years ago
0.0.4
3 years ago
0.0.3
3 years ago
0.0.2
3 years ago
0.0.1
3 years ago