@tspacejs/tokens
v1.0.2
Published
> simple package for scoped API tokens ---
Downloads
6
Readme
@tspacejs/tokens
simple package for scoped API tokens
install
using npm:
$ npm i --save @tspacejs/tokens
or using yarn:
$ yarn add @tspacejs/tokens
usage
import tokens as t from '@tspacejs/tokens';
const tokens = t.Tokens(<typeorm datasource >, {privateKey: 'shhhh'});
const expiration = new Date();
expiration.setDate(expiration.getDate() + 90); // 90 days
const token = tokens.createScopedToken({accountId: 123}, ['posts:write'], expiration, "this is an API token");
// -----------------------------------
await tokens.guard("<token>", ["posts:write"]);
// -----------------------------------
await token.revoke();
better docs coming soon