diff options
Diffstat (limited to 'hooks')
-rw-r--r-- | hooks/isAuthenticated.ts | 7 | ||||
-rw-r--r-- | hooks/requireAuth.ts | 11 | ||||
-rw-r--r-- | hooks/sortByDate.ts | 8 |
3 files changed, 21 insertions, 5 deletions
diff --git a/hooks/isAuthenticated.ts b/hooks/isAuthenticated.ts new file mode 100644 index 0000000..50290c8 --- /dev/null +++ b/hooks/isAuthenticated.ts @@ -0,0 +1,7 @@ +import { HookContext } from '@feathersjs/feathers'; + +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..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; -}; +); diff --git a/hooks/sortByDate.ts b/hooks/sortByDate.ts new file mode 100644 index 0000000..9dd1222 --- /dev/null +++ b/hooks/sortByDate.ts @@ -0,0 +1,8 @@ +import _ from 'lodash'; +import { HookContext } from '@feathersjs/feathers'; + +export default async (context: HookContext): Promise<HookContext> => { + _.set(context, 'params.query.$sort', { createdAt: -1 }); + return context; +}; + |