1.0.5 • Published 5 years ago

userhut-token-decoder v1.0.5

Weekly downloads
9
License
MIT
Repository
github
Last release
5 years ago

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

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago