diff --git a/packages/authentication/lib/hooks/connection.js b/packages/authentication/lib/hooks/connection.js index da0fa31196..1deab628be 100644 --- a/packages/authentication/lib/hooks/connection.js +++ b/packages/authentication/lib/hooks/connection.js @@ -5,23 +5,21 @@ module.exports = (strategy = 'jwt') => { const { method, result: { accessToken }, - params: { provider, connection } + params: { connection } } = context; - if (!connection && (provider === 'socketio' || provider === 'primus')) { - throw new Error(`No connection object found. Please make sure you are using the latest version of '@feathersjs/${provider}' and params.connection is set.`); + if (!connection) { + return context; } - if (connection) { - const { authentication: { accessToken: currentToken } = {} } = connection; + const { authentication = {} } = connection; - if (method === 'remove' && accessToken === currentToken) { - debug('Removing authentication information from real-time connection'); - delete connection.authentication; - } else if (method === 'create' && accessToken) { - debug('Adding authentication information to real-time connection'); - connection.authentication = { strategy, accessToken }; - } + if (method === 'remove' && accessToken === authentication.accessToken) { + debug('Removing authentication information from real-time connection'); + delete connection.authentication; + } else if (method === 'create' && accessToken) { + debug('Adding authentication information to real-time connection'); + connection.authentication = { strategy, accessToken }; } return context; diff --git a/packages/authentication/test/hooks/connection.test.js b/packages/authentication/test/hooks/connection.test.js index 5a2efbdc29..2f545362b6 100644 --- a/packages/authentication/test/hooks/connection.test.js +++ b/packages/authentication/test/hooks/connection.test.js @@ -29,16 +29,6 @@ describe('authentication/hooks/connection', () => { }); }); - it('throws error if connection is not set for expected provider', () => { - return service.create({}, { provider: 'socketio' }) - .then(() => assert.fail('Should never get here')) - .catch(error => { - assert.strictEqual(error.message, `No connection object found. ` + - `Please make sure you are using the latest version of '@feathersjs/socketio' ` + - `and params.connection is set.`); - }); - }); - it('create does nothing when there is no connection', () => { return service.create({}, {}).then(result => { assert.deepStrictEqual(result, {