npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

passwordless-hapi

v0.0.3

Published

Adapter for using passwordless with Hapi web server

Readme

passwordless-hapi

passwordless-hapi is a very thin adapter over top of the passwordless express middleware. It tries to use the base passwordless code and only change the way it interacts with requests, replies, and session. Because of the difference in middleware between Express and Hapi, some functionality feels slightly more awkward.

Dependencies

The only dependency is passwordless. This library currently only aims to support 1.1.1, but it may also work with previous versions. It technically is not constrainted by your Hapi version, although it may not work with really old Hapi versions.

Getting you started

The following should provide a quick-start in using Passwordless and Hapi. If you need more details check out the example, the deep dive, or the documentation. Also, don't hesitate to raise comments and questions on GitHub.

1. Install the module:

Follow instructions on the passwordless repo

$ npm install passwordless-hapi --save

2. Require the needed modules

Follow instructions on the passwordless repo

3. Setup your delivery

Follow instructions on the passwordless repo

4. Initialize Passwordless

Follow instructions on the passwordless repo

5. Tell Passwordless how to deliver a token

Follow instructions on the passwordless repo

6. Setup the hapi plugin

// This code is placed at your hapi server definition.
server.register({
  register: require('passwordless-hapi'),
  // All options are listed here
  options: {
    passwordless: passwordless, // your passwordless instance is required
    onSuccessfulAuth: function(reply, userId) { // anytime a successful validation occurs, this fires
      // perform operations with the user id, like persisting to session
      reply.continue(); // must be called if you want to pass through, otherwise handle the reply
    },
    getUserId: function(user, delivery, callback, req) { // the function that passwordless uses to validate users
      // usually you would want something like:
      User.find({email: user}, callback(ret) {
         if(ret)
            callback(null, ret.id)
         else
            callback(null, null)
      })
      // but you could also do the following
      // if you want to allow anyone:
      // callback(null, user);
    },
    sendTokenSuccessHandler: function(request, reply) {
      // Called after a successful call to sendToken. Advised is to redirect
      reply.response().redirect('/check-your-email');
    },
    sendTokenPath: '/sendtoken' // this is optional if you want to have a custom send token path
  }
});

7. The router

There is a bit of divergence here between the express and hapi version. Rather than setting up middleware for you, the core functionality is handled by Hapi, and you don't need to define custom routes.

8. Login page

All you need is a form where users enter their email address, for example:

<html>
	<body>
		<h1>Login</h1>
		<form action="/sendtoken" method="POST">
			Email:
			<br><input name="user" type="text">
			<br><input type="submit" value="Login">
		</form>
	</body>
</html>

passwordless-hapi will look for a field called user submitted via POST.

9. Protect your pages

passwordless-hapi does not provide middleware to protect your pages. Instead, you can write a server extension that uses session to check for a valid user id.

10. Who is logged in?

passwordless-hapi does not provide middleware on top of the request. You can access the user via your preferred session management code.