diff options
Diffstat (limited to 'hooks/requireAuth.ts')
-rw-r--r-- | hooks/requireAuth.ts | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/hooks/requireAuth.ts b/hooks/requireAuth.ts index 52e8974..ac46e22 100644 --- a/hooks/requireAuth.ts +++ b/hooks/requireAuth.ts @@ -1,10 +1,9 @@ +import { iff, isNot } from 'feathers-hooks-common'; import { NotAuthenticated } from '@feathersjs/errors'; -import { HookContext } from '@feathersjs/feathers'; +import isAuthenticated from './isAuthenticated'; -export default async (context: HookContext): Promise<HookContext> => { - if (!context.params.authenticated) { - throw new NotAuthenticated('This endpoint requires auth!'); - } - return context; -}; +export default iff( + isNot(isAuthenticated), + () => { throw new NotAuthenticated('This endpoint requires auth!') } +); |