@smartnewbs/feathersjs-hook-users
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 ]
}
}