2.3.7 • Published 1 year ago

fusion-plugin-jwt v2.3.7

Weekly downloads
227
License
MIT
Repository
github
Last release
1 year ago

fusion-plugin-jwt

Build status

Session library that uses JSON Web Token and cookies


Table of contents


Installation

yarn add fusion-plugin-jwt

Usage

export default createPlugin({
  deps: {Session: SessionToken},
  middleware() {
    return ({Session}) => {
      return async (ctx, next) => {
        const session = Session.from(ctx);
        session.set('some-key', 'some-value');
        const someValue = session.get('some-key');
        return next();
      }
    });
  }
});

Setup

// src/main.js
import React from 'react';
import App from 'fusion-react';
import JWTSession, {
  SessionSecretToken,
  SessionCookieNameToken,
  SessionCookieExpiresToken
} from 'fusion-plugin-jwt';
import {SessionToken} from 'fusion-tokens';

export default () => {
  const app = new App();
  // ...
  if (__NODE__) {
    app.register(SessionToken, JWTSession);
    app.register(SessionSecretToken, 'some-secret'); // required
    app.register(SessionCookieNameToken, 'some-cookie-name'); // required
    app.register(SessionCookieExpiresToken, 86400); // optional
  }
  // ...
  return app;
}

API

Registration API

Session
import Session from 'fusion-plugin-jwt';

The plugin. Should typically be registered to SessionToken

SessionToken

Typically should be registered with Session. See https://github.com/fusionjs/fusionjs/tree/master/fusion-tokens#sessiontoken

Dependencies

SessionSecretToken
import {SessionSecretToken} from 'fusion-plugin-jwt';

Required. A secret for encrypting the JWT token / cookie. Can typically be a random static value.

Types
type Secret = string;
SessionCookieNameToken
import {SessionCookieNameToken} from 'fusion-plugin-jwt';

Required. A cookie name

Types
type CookieName = string;
SessionCookieExpiresToken
import {SessionCookieExpiresToken} from 'fusion-plugin-jwt';

Required. An expiration time in seconds.

Types
type CookieName = number;

Service API

const session: Session = Session.from((ctx: Context));
Types
type Session = {
  set: (key: string, value: Object | Array | string | number | boolean) => any,
  get: (key: string) => any,
};

session.set

const value = session.set(key:string, val:Object|Array|string|number|boolean);
  • key: string - Required
  • val: Object|Array|string|number|boolean - A serializable value. Required
  • returns value: any

session.get

const value: any = session.get(key: string);
  • key: string - Required
  • returns value: any

Caveats

Note that there's a storage limit of ~4kb since data is stored in the cookie.

2.3.7

1 year ago

2.3.4

1 year ago

2.3.6

1 year ago

2.3.5

1 year ago

2.3.0

1 year ago

2.3.2

1 year ago

2.3.1

1 year ago

2.3.3

1 year ago

2.2.11

1 year ago

2.2.10

2 years ago

2.2.9

2 years ago

2.2.7

2 years ago

2.2.6

2 years ago

2.2.8

2 years ago

2.2.5

2 years ago

2.2.4

2 years ago

2.2.3

2 years ago

2.2.2

2 years ago

2.2.1

2 years ago

2.2.0

3 years ago

2.1.11

3 years ago

2.1.10

3 years ago

2.1.9

3 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.4

4 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

5 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.7

5 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.3.5

6 years ago

0.3.4

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.5

6 years ago

0.1.8

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago