Wrapper around the functionality of jsonwebtoken to easily set and validate JWT tokens in express requests/responses
const jwtInCookie = require("jwt-in-cookie");
jwtInCookie.configure({secret: 'MY_SECRET'});
function (req, res) {
jwtInCookie.setJwtToken(res, data);
...
}
function (req, res) {
jwtInCookie.validateJwtToken(req);
...
}
function (req, res) {
jwtInCookie.clearToken(res);
...
}
config object literal
Configures the instance of jwt-in-cookie
Return: void
secret: string (required), secret to be used to sign the JWTEg:
abcdefghijklmnopqrstuvwxyz1234567890timeoutDuration: string, length of time before signed data expiresEg:
"2 hours","1d","20h",60
Adds payload as a token in the response cookie using configured secret & options
Return: string, token of payload
payload object
cookieOptions object, options that set in the cookie
httpOnly: boolean, javascript can't access the cookieexpires: number, time until the cookie expires (if 0, will expire at end of session)
Clears the jwt token from the response
Return: void
Returns decoded token if request contains a valid JWT in its cookie (must be preceded by jwtInCookie.configure)
Return: object
Encodes payload using configured secret & options
Return: encoded payload
payload object
Retrieves decoded token from the input request's cookie (must be preceded by jwtInCookie.configure)
Return: decoded token