# email-auth

> Email verification for login

Latest version **1.0.0** (published 2017-07-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install email-auth
pnpm add email-auth
yarn add email-auth
bun add email-auth
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-07-12 |
| First published | 2016-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Forbes Lindesay |
| Maintainers | forbeslindesay |

## Links

- npm: https://www.npmjs.com/package/email-auth
- Repository: https://github.com/ForbesLindesay/email-auth
- Homepage: https://github.com/ForbesLindesay/email-auth#readme
- Issues: https://github.com/ForbesLindesay/email-auth/issues
- npm.io page: https://npm.io/package/email-auth

## Dependencies (8)

- [ms](https://npm.io/package/ms.md) ^2.0.0
- [qs](https://npm.io/package/qs.md) ^6.5.0
- [promise](https://npm.io/package/promise.md) ^8.0.1
- [postmark](https://npm.io/package/postmark.md) ^1.4.1
- [@types/ms](https://npm.io/package/@types/ms.md) ^0.7.29
- [@types/qs](https://npm.io/package/@types/qs.md) ^6.5.0
- [@types/node](https://npm.io/package/@types/node.md) ^6.0.81
- [@types/postmark](https://npm.io/package/@types/postmark.md) ^1.3.0

## Recent versions

- 1.0.0 (latest) — 2017-07-12
- 0.0.6 — 2016-11-01
- 0.0.5 — 2016-10-23
- 0.0.4 — 2016-10-23
- 0.0.3 — 2016-10-23
- 0.0.2 — 2016-10-23
- 0.0.1 — 2016-10-23

## README

# email-auth

Email verification for login

[![Build Status](https://img.shields.io/travis/ForbesLindesay/email-auth/master.svg)](https://travis-ci.org/ForbesLindesay/email-auth)
[![Dependency Status](https://img.shields.io/david/ForbesLindesay/email-auth/master.svg)](http://david-dm.org/ForbesLindesay/email-auth)
[![NPM version](https://img.shields.io/npm/v/email-auth.svg)](https://www.npmjs.org/package/email-auth)

## Installation

```
npm install email-auth --save
```

## Usage

```js
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

---
_Source: https://npm.io/package/email-auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
