1.1.0 • Published 4 years ago

epersonate-dev v1.1.0

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

epersonate-node

Official Node Wrapper for ePersonate API.

ePersonate Documentation

Official ePersonate Documentation

Installation

npm install -s @epersonate/epersonate

Usage

Require ePersonate:

const Epersonate = require('@epersonate/epersonate'); 
// Or with ES6 syntax
import * as Epersonate from '@epersonate/epersonate';

const epersonate = new Epersonate.Client({
    token: Env.get('EPERSONATE_TOKEN')
});

Using Personal Access Token

Go to https://epersonate.com/app/settings > Personal Access Token > Create Personal Access Token

Note: Replace EPERSONATE_TOKEN with the newly generated token.

Example Usage

function login(req, res, next) {
    // Your logic.
    (...)
    const impersonation = await epersonate.verify({
        token: req.header('x-epersonate')
    });
    if (!impersonation.valid)
        return next();

    const user = await User.find(impersonation.userId);

    return next();
}

Alternatively, you can pass the request object to epersonate verify method, it will take care of extracting the x-epersonate header or cookie:

    const impersonation = await epersonate.verify({
        request: req
    });

Storing impersonation events

    const impersonation = await epersonate.verify({
        request: req,
        name: req.url,
        metadata: {
            id: req.id,
            method: req.method,
            'foo': 'bar',
            (...)
        }
    });

Running the code locally

gulp babel

Before creating a PR:

gulp lint

Require ePersonate:

const ePersonate = require('./dist/index');

Deploy

Update version in package.json && gulpfile.js

npm publish