aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hooks/isAuthenticated.ts9
-rw-r--r--hooks/requireAuth.ts13
2 files changed, 15 insertions, 7 deletions
diff --git a/hooks/isAuthenticated.ts b/hooks/isAuthenticated.ts
new file mode 100644
index 0000000..d0da8b6
--- /dev/null
+++ b/hooks/isAuthenticated.ts
@@ -0,0 +1,9 @@
+import { HookContext } from '@feathersjs/feathers';
+import { authenticate } from '@feathersjs/authentication';
+
+
+export default async (context: HookContext): Promise<boolean> => {
+ console.log(context.params.authenticated);
+ return context.params.authenticated || false;
+};
+
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!') }
+);