Skip to content

Commit

Permalink
fix(authentication-local): Keep non-objects in protect hook (#2085)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Oct 9, 2020
1 parent d07bf59 commit 5a65e2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
11 changes: 8 additions & 3 deletions packages/authentication-local/src/hooks/protect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import { HookContext } from '@feathersjs/feathers';
export default (...fields: string[]) => (context: HookContext) => {
const result = context.dispatch || context.result;
const o = (current: any) => {
const data = typeof current.toJSON === 'function'
? current.toJSON() : current;
return omit(data, fields);
if (typeof current === 'object' && !Array.isArray(current)) {
const data = typeof current.toJSON === 'function'
? current.toJSON() : current;

return omit(data, fields);
}

return current;
};

if (!result) {
Expand Down
10 changes: 7 additions & 3 deletions packages/authentication-local/test/hooks/protect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ function testOmit (title: string, property: string) {
});
});

it('omits from array', () => {
it('omits from array but only objects (#2053)', () => {
const data = [{
email: 'test1@user.com',
password: 'supersecret'
}, {
email: 'test2@user.com',
password: 'othersecret'
}];
}, [
'one', 'two', 'three'
], 'test'];
const context = {
[property]: data
} as unknown as HookContext;
Expand All @@ -99,7 +101,9 @@ function testOmit (title: string, property: string) {
[property]: data,
dispatch: [
{ email: 'test1@user.com' },
{ email: 'test2@user.com' }
{ email: 'test2@user.com' }, [
'one', 'two', 'three'
], 'test'
]
});
});
Expand Down

0 comments on commit 5a65e2e

Please sign in to comment.