diff options
author | eug-vs <eug-vs@keemail.me> | 2020-06-14 17:09:19 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-06-14 17:12:07 +0300 |
commit | fc4bdecdcd8abc7a2adaeb4b7f209f6930846ffa (patch) | |
tree | 73ffa18ac2cd6fd34344821b080574fc4b95449c | |
parent | 4e7a71671bd21a4138909374b1124d269493551e (diff) | |
download | which-api-fc4bdecdcd8abc7a2adaeb4b7f209f6930846ffa.tar.gz |
feat: use hashPassword hook
-rw-r--r-- | populateDb.ts | 1 | ||||
-rw-r--r-- | services/users/users.hooks.ts | 12 | ||||
-rw-r--r-- | services/users/users.service.ts | 2 |
3 files changed, 15 insertions, 0 deletions
diff --git a/populateDb.ts b/populateDb.ts index 0a89cc9..a21b669 100644 --- a/populateDb.ts +++ b/populateDb.ts @@ -46,6 +46,7 @@ const createPoll = (authorId: string): Promise<PollSchema> => { const createUser = (name: string): Promise<UserSchema> => { return app.service('users').create({ avatarUrl: _.sample(imageUrls) || '', + password: 'supersecret', name }); }; diff --git a/services/users/users.hooks.ts b/services/users/users.hooks.ts new file mode 100644 index 0000000..06cbfde --- /dev/null +++ b/services/users/users.hooks.ts @@ -0,0 +1,12 @@ +import { hooks } from '@feathersjs/authentication-local'; + +const hashPassword = hooks.hashPassword('password'); + +export default { + before: { + create: [hashPassword], + patch: [hashPassword], + update: [hashPassword] + } +}; + diff --git a/services/users/users.service.ts b/services/users/users.service.ts index 988d162..08c347d 100644 --- a/services/users/users.service.ts +++ b/services/users/users.service.ts @@ -1,10 +1,12 @@ import { Application } from '@feathersjs/express'; import service from 'feathers-mongoose'; import Model from '../../models/users/user.model'; +import hooks from './users.hooks'; const UserService = service({ Model }); export default (app: Application): void => { app.use('/users', UserService); + app.service('users').hooks(hooks); }; |