diff options
Diffstat (limited to 'hooks/requireAuth.ts')
-rw-r--r-- | hooks/requireAuth.ts | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/hooks/requireAuth.ts b/hooks/requireAuth.ts index 52e8974..ba08f57 100644 --- a/hooks/requireAuth.ts +++ b/hooks/requireAuth.ts @@ -1,10 +1,11 @@ +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) { +export default iff( + isNot(isAuthenticated), + () => { throw new NotAuthenticated('This endpoint requires auth!'); } - return context; -}; +); |