@smartnewbs/feathersjs-hook-users

Feathersjs hooks for the user service

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
Minified + gzip package size for @smartnewbs/feathersjs-hook-users in KB

Readme

@smartnewbs/feathersjs-hook-users

License Version Node Coverage Status

This lib is for Feathersjs as utility hooks.

Installation

npm install @smartnewbs/featherjs-hook-users --save

firstUserIsRole

The hook will modify hook.data.role with the specified role only if its the first entry in the users service. It is meant to be only used as a before create hook in your users.hooks.js:

const { firstUserIsRole } = require('@smartnewbs/feathersjs-hook-users');
module.exports = {
  before: {
    create: [ firstUserIsRole('ROLE_ADMIN') ]
  }
}

restrictPropertyByRoles

The hook will check the authenticated user's role (hook.params.user.role) against the roles specified. It is meant to be only used as a before hook for the methods create, update and patch.

const { restrictPropertyByRoles } = require('@smartnewbs/feathersjs-hook-users');
module.exports = {
  before: {
    create: [ restrictPropertyByRoles('status', ['ROLE_ADMIN']) ],
    update: [ restrictPropertyByRoles('status', ['ROLE_ADMIN']) ],
    patch: [ restrictPropertyByRoles('status', ['ROLE_ADMIN']) ]
  }
}

extractGoogleProfile

The hook is mean to extract Google OAuth profile and associate the properties to the user model.

hook.data.email = hook.data.google.profile.emails[0].value;
hook.data.name = hook.data.google.profile.displayName;
hook.data.avatar = hook.data.google.profile.photos[0].value;

It is meant to be a before hook for the method create.

const { extractGoogleProfile } = require('@smartnewbs/feathersjs-hook-users');
module.exports = {
  before: {
    create: [ extractGoogleProfile ]
  }
}

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.