This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@forrestjs/service-hash

5.0.3 • Public • Published

@forrestjs/service-hash (deprecated)

🚧 DEPRECATED 🚧

ForrestJS service which helps hashing stuff with bcrypt.

Usage

service-hash decorates the Hooks App Context with a hash.encode() and hash.compare() helpers:

const hooks = require('@forrestjs/core');
hooks.registerAction({
  hook: hooks.FINISH,
  handler: async (args, ctx) => {
    const encoded = await ctx.hash.encode('foo');
    console.log(encoded);

    const isValid = await ctx.hash.compare('foo', encoded);
    console.log(isValid);
  },
});

After the Hooks App initializes, you can simply import the helpers and use it straight:

const { encode, compare } = require('@forrestjs/service-jwt');

const encoded = await ctx.hash.encode('foo');
const isValid = await ctx.hash.compare('foo', encoded);

Configuration

NOTE: the salt setting is optional, if not provided, a new salt will be generated at boot time and logged out as "info" message.

Environment

NOTE: it is important to list service-hash AFTER service-env so that any kind of environment configuration is available to be used.

HASH_ROUNDS=5
HASH_SALT=xxx

Config

registerAction({
  hook: SETTINGS,
  handler: ({ setConfig }) => {
    setConfig('jwt.rounds', 5);
    setConfig('jwt.salt', '$2a$05$EWFE8/77wXdbYuzyx9Golu');
  },
});

Fastify integration

const feature = {
  hook: '$FASTIFY_GET',
  handler: {
    url: '/hash/encode/:input',
    handler: async (request) => request.hash.encode(request.params.input),
  },
};

Package Sidebar

Install

npm i @forrestjs/service-hash

Weekly Downloads

2

Version

5.0.3

License

MIT

Unpacked Size

7.24 kB

Total Files

5

Last publish

Collaborators

  • marcopeg