# @tryghost/magic-link

> ## Install

Latest version **1.0.27** (published 2022-10-05) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @tryghost/magic-link
pnpm add @tryghost/magic-link
yarn add @tryghost/magic-link
bun add @tryghost/magic-link
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.27 |
| Published | 2022-10-05 |
| First published | 2019-09-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 10.2 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Ghost Foundation |
| Maintainers | lenabaidakova, kernalghost, hadret, minimaluminium, ronaldlangeveld, simonbackx, moreofmorris, joeegrigg, sanne-san, djordjevlais, bobvaneck, zimoatghost, allouis, gargol, rishabhgrg, erisds, johnonolan, kevinansfield, cobbspur, aileencgn, jloh, daniellockyer, sam-lord, pauladamdavis |

## Links

- npm: https://www.npmjs.com/package/@tryghost/magic-link
- Repository: https://github.com/TryGhost/Members/tree/main/packages/magic-link
- npm.io page: https://npm.io/package/@tryghost/magic-link

## Dependencies (5)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.5
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1
- [@tryghost/tpl](https://npm.io/package/@tryghost/tpl.md) 0.1.18
- [@tryghost/validator](https://npm.io/package/@tryghost/validator.md) 0.1.29

## Recent versions

- 1.0.27 (latest) — 2022-10-05
- 1.1.0 — 2022-07-15
- 1.0.26 — 2022-05-16
- 1.0.25 — 2022-05-10
- 1.0.24 — 2022-05-03
- 1.0.23 — 2022-05-02
- 1.0.22 — 2022-04-27
- 1.0.21 — 2022-03-11
- 1.0.20 — 2022-03-01
- 1.0.19 — 2022-02-17
- 1.0.18 — 2022-02-15
- 1.0.17 — 2022-01-21
- 1.0.16 — 2022-01-20
- 1.0.15 — 2022-01-10
- 1.0.14 — 2021-10-21
- … 49 more at https://npm.io/package/@tryghost/magic-link/versions

## README

# Magic Link

## Install

`npm install @tryghost/magic-link --save`

or

`yarn add @tryghost/magic-link`


## Usage

```js
const crypto = require('crypto');
const nodemailer = require('nodemailer');
const MagicLink = require('@tryghost/magic-link');

async function main() {
    const jwtSecret = crypto.randomBytes(16).toString('hex');

    // https://nodemailer.com/about/#example
    const testAccount = await nodemailer.createTestAccount();

    const transporter = nodemailer.createTransport({
        host: 'smtp.ethereal.email',
        port: 587,
        secure: false, // true for 465, false for other ports
        auth: {
            user: testAccount.user, // generated ethereal user
            pass: testAccount.pass // generated ethereal password
        }
    }, {
        from: '"Your App" <signin@example.com>',
        subject: 'Whatever'
    });

    const service = MagicLink({
        tokenProvider: new MagicLink.JWTTokenProvider(jwtSecret),
        transporter,
        getSigninURL(token) {
            return `http://example.com/signin?token=${token}`
        }
    });

    /**
     *  POST /signin
     */
    const {url, info} = await service.sendMagicLink({
        email: 'test@example.com',
        tokenData: {
            id: 'some-id'
        }
    });

    // https://nodemailer.com/about/#example
    // Preview only available when sending through an Ethereal account
    console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
    // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...

    /**
     *  GET /signin
     */
    const data = await service.getDataFromToken(token);
    // createSomeKindOfSession(user);
}

main();
```


## Develop

This is a mono repository, managed with [lerna](https://lernajs.io/).

Follow the instructions for the top-level repo.
1. `git clone` this repo & `cd` into it as usual
2. Run `yarn` to install top-level dependencies.


## Run

- `yarn dev`


## Test

- `yarn lint` run just eslint
- `yarn test` run lint and tests




# Copyright & License

Copyright (c) 2013-2022 Ghost Foundation - Released under the [MIT license](LICENSE).

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