aboutsummaryrefslogtreecommitdiff
path: root/services/users/users.hooks.ts
blob: 580d1d21c396cbc16c8113cf7f08fd35352197cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { hooks } from '@feathersjs/authentication-local';
import { HookContext } from '@feathersjs/feathers';

const hashPassword = hooks.hashPassword('password');

const protectPassword = async (context: HookContext): Promise<HookContext> => {
  const { dispatch } = hooks.protect('password')(context);
  context.result = dispatch;
  context.dispatch = dispatch;
  return context;
}

export default {
  after: {
    all: [protectPassword]
  },
  before: {
    create: [hashPassword],
    patch: [hashPassword],
    update: [hashPassword]
  }
};