diff options
Diffstat (limited to 'services/users')
-rw-r--r-- | services/users/users.hooks.ts | 19 | ||||
-rw-r--r-- | services/users/users.service.ts | 2 |
2 files changed, 13 insertions, 8 deletions
diff --git a/services/users/users.hooks.ts b/services/users/users.hooks.ts index ee1ae1c..48843be 100644 --- a/services/users/users.hooks.ts +++ b/services/users/users.hooks.ts @@ -1,22 +1,27 @@ +import _ from 'lodash'; import { hooks } from '@feathersjs/authentication-local'; +import { discard } from 'feathers-hooks-common'; import { HookContext } from '@feathersjs/feathers'; const hashPassword = hooks.hashPassword('password'); -const localDispatch = async (context: HookContext): Promise<HookContext> => { - context.result = context.dispatch; +const ignoreCaseRegex = async (context: HookContext): Promise<HookContext> => { + context.params.query = _.mapValues(context.params.query, data => { + return _.set(data, '$options', 'i'); + }); return context; }; export default { after: { - all: [hooks.protect('password')], - get: [localDispatch] // Protect password from local get's + all: hooks.protect('password'), + get: discard('password') // Protect password from local get's }, before: { - create: [hashPassword], - patch: [hashPassword], - update: [hashPassword] + find: ignoreCaseRegex, + create: hashPassword, + patch: hashPassword, + update: hashPassword } }; diff --git a/services/users/users.service.ts b/services/users/users.service.ts index 08c347d..77eb9fd 100644 --- a/services/users/users.service.ts +++ b/services/users/users.service.ts @@ -3,7 +3,7 @@ import service from 'feathers-mongoose'; import Model from '../../models/users/user.model'; import hooks from './users.hooks'; -const UserService = service({ Model }); +const UserService = service({ Model, whitelist: ['$options', '$regex'] }); export default (app: Application): void => { app.use('/users', UserService); |