truesign-fastify-hook
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Welcome to truesign-fastify-hook 👋

Version License: ISC Twitter: julipan37

This is a simple Fastify hook for handling requests with Truesign tokens on query string.

Usage example

import { getTruesignHook, TruesignHookConfig } from 'truesign-fastify-hook';

function shouldAcceptToken(
  decryptedToken: DecryptedToken, 
  config: TruesignHookConfig
): boolean {
  if (((Date.now() - decryptedToken.timestamp) / 1000) > config.tokenExpirationTimeSeconds) return false;
  return true;
}

const trueSignOptions: TruesignHookConfig = {
  shouldAcceptToken,
  encryptionKey: process.env.TRUESIGN_KEY,
  allowUnauthenticated: false,
  // we can add more configuration so we have this available in shouldAcceptToekn function
  tokenExpirationTimeSeconds: 30,
};

// when dealing with routes
fastify.addHook('onRequest', getTruesignHook(trueSignOptions));

// or in each secured route
fastify.route({
  method: 'GET',
  url: '/',
  schema: { ... },
  onRequest: getTruesignHook(trueSignOptions),
  // or
  preValidation: getTruesignHook(trueSignOptions),
  // or
  // or others
});

The decrypted token interface is a copy from Truesign docs.

This is a simple package for a simple use case. If you want to extend it to more use cases, plese contribute!

Install

npm install

Run tests

npm run test

Author

👤 Julian Toledo

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator

Package Sidebar

Install

npm i truesign-fastify-hook

Weekly Downloads

2

Version

1.0.0

License

ISC

Unpacked Size

31.3 kB

Total Files

13

Last publish

Collaborators

  • julianitor