Skip to content

Commit 69b2121

Browse files
committed
feat: add isAuthenticated hook
1 parent 5b4b649 commit 69b2121

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

hooks/isAuthenticated.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { HookContext } from '@feathersjs/feathers';
2+
import { authenticate } from '@feathersjs/authentication';
3+
4+
5+
export default async (context: HookContext): Promise<boolean> => {
6+
console.log(context.params.authenticated);
7+
return context.params.authenticated || false;
8+
};
9+

hooks/requireAuth.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import { iff, isNot } from 'feathers-hooks-common';
12
import { NotAuthenticated } from '@feathersjs/errors';
2-
import { HookContext } from '@feathersjs/feathers';
3+
import isAuthenticated from './isAuthenticated';
34

4-
export default async (context: HookContext): Promise<HookContext> => {
5-
if (!context.params.authenticated) {
6-
throw new NotAuthenticated('This endpoint requires auth!');
7-
}
8-
return context;
9-
};
5+
export default iff(
6+
isNot(isAuthenticated),
7+
() => { throw new NotAuthenticated('This endpoint requires auth!') }
8+
);
109

0 commit comments

Comments
 (0)