Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jwt-koa

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jwt-koa

## Simple mini-lib for secured APIs and servers with Koa and JWT.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
increased by1100%
Maintainers
1
Weekly downloads
 
Created
Source

jwt-koa

Simple mini-lib for secured APIs and servers with Koa and JWT.

NPM version Open Source Love

What includes

  • Middleware for checking request headers for token
  • CreateToken function for creating token

Setup

Install it:

npm install jwt-koa --save

or

yarn add jwt-koa

Usage

Import
const jwtKoa = require('jwt-koa');
Set secret key for JWT
process.env.secret = 'SECRET';
Set middleware to secured Router
securedRouter.use(jwtKoa.middleware);
securedRouter.get('/secured', async ctx => {
    ctx.body = { data: 'Secured Data' };
});
Send token to client
notSecuredRouter.post('/send', async ctx => {
    const token = jwtKoa.createToken({ tokenData: 'tokenData' });
    // You can set expire time (3000 by default)
    const tokenWithExpireTime = jwtKoa.createToken(
        { tokenData: 'tokenData' },
        5000
    );
    ctx.response.body = token;
});

Client-side example

fetch('/secured', { method: 'GET', headers: { Authorization: /* There is token from backend*/ } })
    .then(j => j.json())
    .then(data => /* There is secured data*/);
Usage example

FAQs

Package last updated on 04 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc