Userhut token decoder for Node
npm install --save userhut-token-decoder jsonwebtoken
// Initialize library
const TokenDecoder = require("userhut-token-decoder");
const tokenDecoder = new TokenDecoder({
poolId: "your-pool-id",
publicKey: "your-public-key"
});
// Decode token
const token = ctx.request.headers["authorization"];
const decoded = tokenDecoder.decode(token);
const TokenDecoder = require("userhut-token-decoder");
const tokenDecoder = new TokenDecoder({
poolId: process.env.APP_USERHUT_POOL_ID,
publicKey: process.env.APP_USERHUT_PUBLIC_KEY_B64
});
module.exports = async (ctx, next) => {
const token = ctx.request.headers["authorization"];
const user = tokenDecoder.decode(token);
ctx.state.user = user;
return next();
};