1 | import { HookContext } from '@feathersjs/feathers'
|
2 | import hashPassword from './hooks/hash-password'
|
3 | import protect from './hooks/protect'
|
4 | import { LocalStrategy } from './strategy'
|
5 |
|
6 | export const hooks = { hashPassword, protect }
|
7 | export { LocalStrategy }
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export const passwordHash =
|
17 | (options: { service?: string; strategy: string }) =>
|
18 | async <H extends HookContext<any, any>>(value: string | undefined, _data: any, context: H) => {
|
19 | if (value === undefined) {
|
20 | return value
|
21 | }
|
22 |
|
23 | const { app, params } = context
|
24 | const authService = app.defaultAuthentication(options.service)
|
25 | const localStrategy = authService.getStrategy(options.strategy) as LocalStrategy
|
26 |
|
27 | return localStrategy.hashPassword(value, params)
|
28 | }
|