diff --git a/packages/authentication-local/src/hooks/protect.ts b/packages/authentication-local/src/hooks/protect.ts index c430927f69..6114544d70 100644 --- a/packages/authentication-local/src/hooks/protect.ts +++ b/packages/authentication-local/src/hooks/protect.ts @@ -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) { diff --git a/packages/authentication-local/test/hooks/protect.test.ts b/packages/authentication-local/test/hooks/protect.test.ts index d8607b15a2..994c579402 100644 --- a/packages/authentication-local/test/hooks/protect.test.ts +++ b/packages/authentication-local/test/hooks/protect.test.ts @@ -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; @@ -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' ] }); });