E5F4 fix(authentication-local): Keep non-objects in protect hook by daffl · Pull Request #2085 · feathersjs/feathers · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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