With PNPM:pnpm i node-tokenizeWith Yarn:yarn add node-tokenizeWith NPM:npm i node-tokenize
How to use it
import Tokenize from 'node-tokenize'import Otp from 'node-tokenize/otp'const tokenize = new Tokenize('Very strong and secure secret')console.log(tokenize.generate('account_id')) // xxxxxxxx.xxxxxxxxxxx.xxxxxxxxxconsole.log(tokenize.generate('account_id', 'prefix')) // prefix.xxxxxxxx.xxxxxxxxxxx.xxxxxxxxx// Returns the account, or null if the token is invalidconsole.log(tokenize.validate('xxxxxxxx.xxxxxxxxxxx.xxxxxxxxx', () => ({ tokensValidSince: 0 })))// Get an OTP keyconsole.log(Otp.generateKey()) // You just need to save the base32 key in database
For specifications about how to use Tokenize in general, please refer to the top-level
README.