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 authored Oct 9, 2020
1 parent 6369f0b commit 8977bb7
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: '[email protected]',
password: 'supersecret'
}, {
email: '[email protected]',
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: '[email protected]' },
{ email: '[email protected]' }
{ email: '[email protected]' }, [
'one', 'two', 'three'
], 'test'
]
});
});
Expand Down

0 comments on commit 8977bb7

Please sign in to comment.