1.0.3 • Published 12 months ago

vstring-express v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
12 months ago

vstring-express v1.0.0

Simple verification string management for Express.


Quick Start:

  1. Add vstring.intercept to your Express routes:
const Vstring = require('vstring-express');

const vstring = new Vstring();

const app = express();

app.get('/vstring/:vstring', vstring.intercept);
  1. Generate a new verification string, defining an action, a ttl (in milliseconds), and store any other data you'll need to handle it:
const {string, expires} = await vstring.newString({
    action: 'verify-email',
    ttl: 14 * 24 * 60 * 60 * 1000, // 14 days
    email:'someone@example.com'}
});
// returns string: "65567b7d78df67ed5..." (64 digits)
  1. Email a link to the user:
const link = `http://${host}/vstring/${string}`;

sendEmail({
    to: 'someone@example.com',
    content: `Click: ${link}`,
});
  1. Add a handler. Your additional data will be exposed on the request object as req.vparams:
vstring.handle('verify-email', (req, res, next) => {
    const {email} = req.vparams;
    await markVerified(email);
    res.redirect('/email-verified.html');
})

Notes:

  • Expired strings are deleted automatically and will not execute the handler functions. You can assume in the handler function that the string is valid and was unexpired.
  • Only one handler function is possible per action.
  • Handler functions are like regular express Middleware:
    • They are executed with (req, res, next)
    • You must complete the request or pass it along, or it will be left hanging. res.send(), res.end(), next(), etc.

©2024 by Gregory Everett Brandon. See LICENSE.

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago

1.0.3

12 months ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago