diff --git a/packages/authentication-local/lib/hooks/protect.js b/packages/authentication-local/lib/hooks/protect.js index caf044a3ca..0f56db20a5 100644 --- a/packages/authentication-local/lib/hooks/protect.js +++ b/packages/authentication-local/lib/hooks/protect.js @@ -11,7 +11,7 @@ module.exports = function (...fields) { if (Array.isArray(result)) { context.dispatch = result.map(o); - } else if (result.data) { + } else if (result.data && context.method === 'find') { context.dispatch = Object.assign({}, result, { data: result.data.map(o) }); diff --git a/packages/authentication-local/test/hooks/protect.test.js b/packages/authentication-local/test/hooks/protect.test.js index f6963c07aa..ae3233b325 100644 --- a/packages/authentication-local/test/hooks/protect.test.js +++ b/packages/authentication-local/test/hooks/protect.test.js @@ -24,6 +24,23 @@ function testOmit (title, property) { }); }); + it('handles `data` property only for find', () => { + const data = { + email: 'test@user.com', + password: 'supersecret', + data: 'yes' + }; + const context = { + [property]: data + }; + const result = fn(context); + + expect(result).to.deep.equal({ + [property]: data, + dispatch: { email: 'test@user.com', data: 'yes' } + }); + }); + it('omits from array', () => { const data = [{ email: 'test1@user.com', @@ -58,11 +75,13 @@ function testOmit (title, property) { }] }; const context = { + method: 'find', [property]: data }; const result = fn(context); expect(result).to.deep.equal({ + method: 'find', [property]: data, dispatch: { total: 2,