Skip to content

byteboomers/userhut-token-decoder-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

userhut-token-decoder-node

Userhut token decoder for Node

Installation

NPM

npm install --save userhut-token-decoder jsonwebtoken

npm package link

Usage

// 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);

Koa middleware

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();
};

Releases

No releases published

Packages

No packages published