File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 1
1
import _ from 'lodash' ;
2
2
import { hooks } from '@feathersjs/authentication-local' ;
3
- import { discard } from 'feathers-hooks-common' ;
3
+ import { discard , disallow } from 'feathers-hooks-common' ;
4
4
import { HookContext } from '@feathersjs/feathers' ;
5
+ import { NotAuthenticated } from '@feathersjs/errors' ;
6
+ import requireAuth from '../../hooks/requireAuth' ;
5
7
6
8
const hashPassword = hooks . hashPassword ( 'password' ) ;
7
9
@@ -12,6 +14,13 @@ const ignoreCaseRegex = async (context: HookContext): Promise<HookContext> => {
12
14
return context ;
13
15
} ;
14
16
17
+ const compareUser = async ( context : HookContext ) : Promise < HookContext > => {
18
+ if ( context . arguments [ 0 ] != context . params . user . _id ) {
19
+ throw new NotAuthenticated ( 'You can only PATCH/UPDATE your own user!' ) ;
20
+ }
21
+ return context ;
22
+ }
23
+
15
24
export default {
16
25
after : {
17
26
all : hooks . protect ( 'password' ) ,
@@ -20,8 +29,9 @@ export default {
20
29
before : {
21
30
find : ignoreCaseRegex ,
22
31
create : hashPassword ,
23
- patch : hashPassword ,
24
- update : hashPassword
32
+ patch : [ hashPassword , requireAuth , compareUser ] ,
33
+ update : [ hashPassword , requireAuth , compareUser ] ,
34
+ remove : disallow ( 'external' )
25
35
}
26
36
} ;
27
37
You can’t perform that action at this time.
0 commit comments