Parameters
db
Object – instance of a level db. See https://npmjs.com/levelconfig
Object – configuration objectconfig.algorithm
string – Optional. JWA algorithm, default isHS256
(HMAC/SHA256 with secret). You must specify your key type if using a keypair.config.secret
string – Optional. Secret used for signing and verifying tokensconfig.publicKey
string – Optional. Public key used to sign tokensconfig.privateKey
string – Optional. Private key used to verify tokens
Examples
var resetTokens = require('township-reset-password-token')
var reset = resetTokens(db, {
secret: 'choose something more secret'
})
reset.create({ accountKey: 'key for an account' }, function (err, token) {
if (err) return console.log(err)
reset.confirm({ accountKey: 'key for an account', token: token }, function (err) {
if (err) return console.log('token not confirmed')
console.log('token confirmed')
})
})
create a password reset token
Parameters
options
Object – required options objectoptions.accountKey
String – required key for the account that is being reset
Examples
reset.create({ accountKey: 'key for an account' }, function (err, token) {
if (err) return console.log(err)
// send token in email
})
confirm a password reset token
Parameters
options
Object – required options objectoptions.accountKey
String – required key for the account that is being reset
Examples
// receive token via http request
reset.confirm({ accountKey: 'key for an account', token: token }, function (err) {
if (err) return console.log('token not confirmed')
console.log('token confirmed')
})