@smartnewbs/feathersjs-hook-users

1.1.2 • Public • Published

@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 ]
  }
}

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.20latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.20
1.1.11
1.1.01
1.0.00

Package Sidebar

Install

npm i @smartnewbs/feathersjs-hook-users

Weekly Downloads

2

Version

1.1.2

License

MIT

Unpacked Size

23.4 kB

Total Files

14

Last publish

Collaborators

  • pguilbault