Skip to content
hapi plugin that shortcuts “request.auth.credentials” to “request.user”
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib register once Aug 20, 2018
.travis.yml initial Apr 3, 2018

hapi-request-user logo

hapi plugin that shortcuts “request.auth.credentials” to “request.user”

Installation · Usage · Plugin Options

Build Status Known Vulnerabilities hapi-request-user Version Greenkeeper badge

Follow @marcuspoehls for updates!

Development of this hapi plugin is supported by Future Studio University 🚀
Join the Future Studio University and Skyrocket in Node.js


A hapi plugin that shortcuts access to the authenticated user from request.auth.credentials to request.user.

Access the authenticated user in request lifecycle methods, like this:

(request, h) => {
  const user = request.user  // instead of "request.auth.credentials"

  // use the user object


hapi v17 and Node.js v8 (or newer)

This plugin requires hapi v17 (or later) and uses async/await which requires Node.js v8 or newer.


Add hapi-request-user as a dependency to your project:

# NPM v5 users, this way is yours
npm i hapi-request-user

# you’re using NPM v4:
npm i -S hapi-request-user


hapi-request-user is enabled by default.

The most straight forward way to register the hapi-request-user plugin:

await server.register({
  plugin: require('hapi-request-user'),

Plugin Registration Options

The following plugin options allow you to customize the default behavior of hapi-request-user:

  • enabled: (boolean), default: true — by default, the plugin is enabled and decorates request.user with the authenticated user credentials
await server.register({
  plugin: require('hapi-request-user'),
  options: {
    enabled: true

Route Handler Options

The following plugin options on individual route handlers allow you to customize the behavior of hapi-request-user:

  • enabled: (boolean) — tells the plugin to disable (false) request.user decoration for this route handler

The plugin configuration can be customized for single routes using the hapi-request-user key:

  plugin: require('hapi-request-user') // enabled by default

// Within your route handler functions, you can access the location like this
  method: 'GET',
  path: '/',
  config: {
    plugins: {
      'hapi-request-user': {
        enabled: false
    handler: (request, h) => {
      const user = request.user
      // "user" will be undefined when disabling "hapi-request-user"

      return { your: 'value' }

Feature Requests

Do you miss a feature? Please don’t hesitate to create an issue with a short description of your desired addition to this plugin.

Links & Resources


  1. Create a fork
  2. Create your feature branch: git checkout -b my-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request 🚀


MIT © Future Studio  ·  GitHub @futurestudio  ·  Twitter @futurestud_io

You can’t perform that action at this time.