Socket
Book a DemoInstallSign in
Socket

koa-jwt-session

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-jwt-session

Barebone JWT Session management for Koa

0.1.2
latest
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

JWT (JSON Web Token) Session Middleware for Koa

NPM version build status Test coverage npm download

Barebone JWT based session for Koa 2. Tests and configurable options comming soon.

The API is exposed on the context object (this) inside downstream middlewares.

Getting started

import JWTSession from 'koa-jwt-session';
import Koa from 'koa';
const app = new Koa();
app.use(jwtAuth(app, {
  secret: "Shhhha",
  signed: false, // Default to false
  httpOnly: false, // Default to false
  domain: process.env.SESSIONS_SCOPE // Cookie scope. Must be set
}));

// Generate a Session from a controller (route handler)
async function(ctx, next) {
  const formFields = await parse(ctx)
  // store session
  const data = ctx.JWTSession.generate({_id: formFields._id, nickname: formFields.nickname});
}

// Validating a session from a controller (route handler)
async function(ctx, next) {
  const authed = ctx.JWTSession.authed();
  if ( authed ) {
    // Do something that requires auth
  } else {
    // Handle error
  }

API

  • generate(payload)
  • get()
  • set()
  • clear()
  • authed()

Keywords

koa

FAQs

Package last updated on 04 Jun 2016

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.