From 69b212128435cab2919f642fd8352b0b6cf93f83 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 27 Jun 2020 16:25:59 +0300 Subject: feat: add isAuthenticated hook --- hooks/requireAuth.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'hooks/requireAuth.ts') 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 => { - 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!') } +); -- cgit v1.2.3