Socket
Book a DemoInstallSign in
Socket

email-auth

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

email-auth

Email verification for login

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

email-auth

Email verification for login

Build Status Dependency Status NPM version

Installation

npm install email-auth --save

Usage

const emailAuth = require('email-auth');

// this should be a database really
let nextID = 0;
const tokens = {};

const client = createClient({
  saveToken({email, token, expiry}) {
    // save the token and return the id of the saved token, this can return a Promise
    const id = nextID++;
    tokens[id] = {email, token, expiry};
    return id;
  },
  getTokenByID(id) {
    // get the token at that id, can return a Promise
    return tokens[id];
  },
  sendEmail({toAddress, url}) {
    // send the message using to the to email asking the user to click on the url
  },
});

// to send verification e-mail
client.sendMessage('forbes@lindesay.co.uk', 'https://example.com').done();

// to verify/complete a login
app.get('/', (req, res, next) => {
  if (req.query.token_id && req.query.token) {
    client.verifyToken(req.query.token_id, req.query.token).done(email => {
      // log the user in
    }, next);
  }
  // show the user a login page
})

License

MIT

FAQs

Package last updated on 12 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts