Portier client for Node.js
Switch branches/tags
Nothing to show
Clone or download
Latest commit 1ffa09c Mar 12, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Update standard.js Mar 12, 2018
.gitignore Ignore package-lock.json Jan 5, 2018
.travis.yml Add a Travis CI config Jan 5, 2018
LICENSE Update copyright year Jan 5, 2018
README.md Also update the example to use standardjs styling Jan 5, 2018
index.js Expand normalization tests Jan 8, 2018
package.json Version 0.3.2 Mar 12, 2018
test.js Expand normalization tests Jan 8, 2018

README.md

portier-node

A Portier client library for Node.js

Example

const express = require('express')
const formParser = require('body-parser').urlencoded({ extended: false })
const PortierClient = require('portier')

const portier = new PortierClient({
  redirectUri: 'http://localhost:8000/verify'
})

const app = express()

app.get('/', (req, res) => {
  res.type('html').end(`
    <p>Enter your email address:</p>
    <form method="post" action="/auth">
      <input name="email" type="email">
      <button type="submit">Login</button>
    </form>
  `)
})

app.post('/auth', formParser, (req, res, next) => {
  portier.authenticate(req.body.email, (err, authUrl) => {
    if (err) return next(err)
    res.redirect(303, authUrl)
  })
})

app.post('/verify', formParser, (req, res, next) => {
  portier.verify(req.body.id_token, (err, email) => {
    if (err) return next(err)
    res.type('html').end(`
      <p>Verified email address ${email}!</p>
    `)
  })
})

app.listen(8000)