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 🙏

© 2026 – Pkg Stats / Ryan Hefner

hapi-account

v6.2.8

Published

Users management

Downloads

67

Readme

Build Status Coverage Status

Hapi account

A REST api for accounts built for hapi server with Bearer token authentication using hapi-beaer-token-atuh and
database for storage of accounts using waterline. Default adapter is sails-disk

The login route with credentials user and password returns a token which will expire unless it is renewed by calling renewToken route within valid time period for the token. This time period can be set by the user.

Features

  • Create and login user via facebook or google
  • Bearer token auth via providing cookie with token or setting Authorization in header to `Bearer {token uuid}
  • Automatic deletion of expired tokens
  • Token renewal on calling renewToken within token valid time period
  • Endpoints for email verification and password reset
  • Add custom pre and post calls to each route.
  • Documentation of routes can be shown with hapi-swagger.

Installation

npm install --save hapi-account

Usage

'use strict'

const Hapi = require( 'hapi' );
const adapter = require('sails-disk');

const server = new Hapi.Server({);

server.register( {
    plugin: require( 'hapi-account' ),
    options: { 
        accountVerified:false,
        basePath: "account",
        events:[
          {type: 'onPostCreate', method:(request, next)=>{...the madgic}}  
          {type: 'onPostForgotPassword', method:(request, next)=>{...the madgic}}                  
        ] ,
    }
});

Facebook login

To get your options.facebook.app_id and options.facebook.app_secret got to Facebook for developers. Login to an account and go to My Apps. Either user keys from an an existing app or create a new one. App id and secret can be found under settings

Google login

To get your options.google.client_id go to Google cloud console and login. Choose and existing project in the top bar or create a new one. Go to APIs & Services to create or use existing client id

Email

Get your preferred transporter for nodmailer and add to options.email.transporter

Routes

Routes can be viewed using hapi-swagger

Options

See options

API

routes

routes~routes()

  • {options.basePath}/changePassword {POST}
  • {options.basePath}/forgotPassword {POST}
  • {options.basePath}/create {POST}
  • {options.basePath}/createFacebook {POST}
  • {options.basePath}/createGoogle {POST}
  • {options.basePath}/login {POST}
  • {options.basePath}/loginFacebook {POST}
  • {options.basePath}/loginGoogle {POST}
  • {options.basePath}/logout {POST}
  • {options.basePath}/renewToken {POST}
  • {options.basePath}/resetPassword {POST}
  • {options.basePath}/updateScope {POST}
  • {options.basePath}/verifyAccount {POST}

Kind: inner method of routes

controller

controller~auth()

Handler for login, renewToken, loginFacebook and loginGoogle route

return

  • response {json}
    • token token uuid
    • expires_in time to token expiration
  • header
    • cookie token uuid as cookie. If x-forwarded-proto == https then secure

Kind: inner method of controller

controller~changePassword()

Handler for change password route

  • request hapi server request object
  • reply hapi server reply object

return {promise}

Kind: inner method of controller

controller~create()

Handler for create route. Used for routes create, createFacebook and createGoogle.

return

  • response {string} Created
  • code 201

Kind: inner method of controller

controller~forgotPassword()

Handler for forgotPassword route

return

  • response {string} Forgot token created

Kind: inner method of controller

controller~logout()

Handler for logout route

return

  • response {string} Logged out

Kind: inner method of controller

controller~renewToken()

Handler for renew token route.

return

  • response {json}
    • token token uuid
    • expires_in time to token expiration
  • header
    • cookie token uuid as cookie. If x-forwarded-proto == https then secure

Kind: inner method of controller

controller~resetPassword()

Handler for resetPassword route

return

  • response {string} Password updated

Kind: inner method of controller

controller~updateScope()

Handler to set an account scope

return

  • response {string} Scope updated

Kind: inner method of controller

controller~verifyAccount()

Handler for verifyAccount route

return

  • response {string} Account verified

Kind: inner method of controller

controller

controller~auth()

Handler for login, renewToken, loginFacebook and loginGoogle route

return

  • response {json}
    • token token uuid
    • expires_in time to token expiration
  • header
    • cookie token uuid as cookie. If x-forwarded-proto == https then secure

Kind: inner method of controller

controller~changePassword()

Handler for change password route

  • request hapi server request object
  • reply hapi server reply object

return {promise}

Kind: inner method of controller

controller~create()

Handler for create route. Used for routes create, createFacebook and createGoogle.

return

  • response {string} Created
  • code 201

Kind: inner method of controller

controller~forgotPassword()

Handler for forgotPassword route

return

  • response {string} Forgot token created

Kind: inner method of controller

controller~logout()

Handler for logout route

return

  • response {string} Logged out

Kind: inner method of controller

controller~renewToken()

Handler for renew token route.

return

  • response {json}
    • token token uuid
    • expires_in time to token expiration
  • header
    • cookie token uuid as cookie. If x-forwarded-proto == https then secure

Kind: inner method of controller

controller~resetPassword()

Handler for resetPassword route

return

  • response {string} Password updated

Kind: inner method of controller

controller~updateScope()

Handler to set an account scope

return

  • response {string} Scope updated

Kind: inner method of controller

controller~verifyAccount()

Handler for verifyAccount route

return

  • response {string} Account verified

Kind: inner method of controller

Tests

Unittests

npm run test

Manual test google and facebook

Go to lib/test/manual Run npm install Copy sample.env to .env cp sample.env .env Open .env and add facebook and google credentials

Go to http://locahost:2000

Routes can be viewed at http://localhost:2000/documentation

Contributing

Feel free to submit issues and pull request on bugs or feature request.

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.