0.5.1 • Published 3 years ago

@restlessness/auth-jwt v0.5.1

Weekly downloads
8
License
MIT
Repository
github
Last release
3 years ago

@restlessness/auth-jwt npm version

Installation

From you restlessness project root run:

$ # Install node package
$ npm i @restlessness/auth-jwt
$
$ # Add it to the project using the restlessness cli
$ restlessness add-auth @restlessness/auth-jwt

The add-auth command adds the package to the project and creates a JwtSession model class, representing the auth session. The model class already includes convenience methods to serialize and deserialize the session object.

Environment variables

NameDescription
RLN_AUTH_JWT_SECRETSecret used to create/verify jwt tokens

The add-auth command also adds parametric environment variables to the .env files present in the project.

Example .env.production file:

RLN_AUTH_JWT_SECRET=${RLN_AUTH_JWT_SECRET_PRODUCTION}

Then is possible to set the variable by setting RLN_AUTH_JWT_SECRET_PRODUCTION or setting RLN_AUTH_JWT_SECRET directly.

Usage

The JwtSession class created by the add-auth command can be modified to include the needed information on the token.

Example:

// src/models/JwtSession/index.ts

export default class JwtSession {
  ['constructor']: typeof JwtSession
  id: string
  name: string
  permissions: string[]

  // ...
};

Then is possible to create a session:

// ...
const session = new JwtSession();
session.id = myId;
session.name = 'Arthur';
session.permissions = [];

const serialized = session.serialize();
const deserialized = JwtSession.deserialize(serialized);
// ...
0.5.1

3 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago

0.0.0

4 years ago