File tree Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Expand file tree Collapse file tree 4 files changed +25
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { HookContext } from '@feathersjs/feathers' ;
2
+
3
+ export default async ( context : HookContext ) : Promise < HookContext > => {
4
+ if ( ! context . params . user ) throw new Error ( 'This endpoint requires auth!' ) ;
5
+ return context ;
6
+ } ;
7
+
Original file line number Diff line number Diff line change
1
+ import { HookContext } from '@feathersjs/feathers' ;
2
+ import { authenticate } from '@feathersjs/authentication' ;
3
+
4
+
5
+ export default async ( context : HookContext ) : Promise < HookContext > => {
6
+ return authenticate ( 'jwt' ) ( context ) . catch ( ( ) => context ) ;
7
+ } ;
8
+
Original file line number Diff line number Diff line change @@ -5,11 +5,19 @@ import Profiles from './profiles/profiles.service';
5
5
import Votes from './votes/votes.service' ;
6
6
import Auth from './auth/auth.service' ;
7
7
8
+ import tryAuthenticate from '../hooks/tryAuthenticate' ;
9
+
8
10
export default ( app : Application ) : void => {
9
11
app . configure ( Auth ) ;
10
12
app . configure ( Users ) ;
11
13
app . configure ( Polls ) ;
12
14
app . configure ( Profiles ) ;
13
15
app . configure ( Votes ) ;
16
+
17
+ app . hooks ( {
18
+ before : {
19
+ all : tryAuthenticate
20
+ }
21
+ } )
14
22
} ;
15
23
Original file line number Diff line number Diff line change 1
1
import { HookContext } from '@feathersjs/feathers' ;
2
- import { authenticate } from '@feathersjs/authentication ' ;
2
+ import requireAuth from '../../hooks/requireAuth ' ;
3
3
4
4
const addUserId = async ( context : HookContext ) : Promise < HookContext > => {
5
5
const { params : { user} } = context ;
@@ -9,7 +9,7 @@ const addUserId = async (context: HookContext): Promise<HookContext> => {
9
9
10
10
export default {
11
11
before : {
12
- create : [ authenticate ( 'jwt' ) , addUserId ]
12
+ create : [ requireAuth , addUserId ]
13
13
}
14
14
} ;
15
15
You can’t perform that action at this time.
0 commit comments