aboutsummaryrefslogtreecommitdiff
path: root/hooks/requireAuth.ts
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-06-27 16:25:59 +0300
committereug-vs <eug-vs@keemail.me>2020-06-27 16:25:59 +0300
commit69b212128435cab2919f642fd8352b0b6cf93f83 (patch)
tree83ea84458cd85e991c8904357ae0ec62ce67a28f /hooks/requireAuth.ts
parent5b4b64905a1b59002bbd1edfdc77c9e422e33334 (diff)
downloadwhich-api-69b212128435cab2919f642fd8352b0b6cf93f83.tar.gz
feat: add isAuthenticated hook
Diffstat (limited to 'hooks/requireAuth.ts')
-rw-r--r--hooks/requireAuth.ts13
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!') }
+);