0.1.2 • Published 8 years ago

koa-jwt-session v0.1.2

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

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()
0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago