Skip to content
This repository has been archived by the owner on Jun 14, 2023. It is now read-only.

Latest commit

 

History

History
68 lines (48 loc) · 2.84 KB

File metadata and controls

68 lines (48 loc) · 2.84 KB

townshipResetPasswordToken

Parameters

  • db Object – instance of a level db. See https://npmjs.com/level
  • config Object – configuration object
    • config.algorithm stringOptional. JWA algorithm, default is HS256 (HMAC/SHA256 with secret). You must specify your key type if using a keypair.
    • config.secret stringOptional. Secret used for signing and verifying tokens
    • config.publicKey stringOptional. Public key used to sign tokens
    • config.privateKey stringOptional. 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

create a password reset token

Parameters

  • options Object – required options object
    • options.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

confirm a password reset token

Parameters

  • options Object – required options object
    • options.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')
})