diff --git a/packages/transport-commons/src/socket/index.ts b/packages/transport-commons/src/socket/index.ts index 71ab6c8abe..09e625ee79 100644 --- a/packages/transport-commons/src/socket/index.ts +++ b/packages/transport-commons/src/socket/index.ts @@ -43,6 +43,13 @@ export function socket ({ done, emit, socketKey, getParams }: SocketOptions) { runMethod(app, getParams(connection), path, method, args); }); } + + connection.on('authenticate', (...args: any[]) => { + if (app.get('defaultAuthentication')) { + debug('Got legacy authenticate event'); + runMethod(app, getParams(connection), app.get('defaultAuthentication'), 'create', args); + } + }); })); // Legacy `socket.emit('serviceName::methodName', ...args)` handlers diff --git a/packages/transport-commons/test/socket/index.test.ts b/packages/transport-commons/test/socket/index.test.ts index b4e0e75dad..5644acb736 100644 --- a/packages/transport-commons/test/socket/index.test.ts +++ b/packages/transport-commons/test/socket/index.test.ts @@ -113,6 +113,32 @@ describe('@feathersjs/transport-commons', () => { }); describe('legacy method socket event format', () => { + it('legacy `authenticate`', done => { + const socket = new EventEmitter(); + const data = { + test: 'data' + }; + + app.set('defaultAuthentication', 'myservice'); + provider.emit('connection', socket); + + socket.emit('authenticate', data, (error: any, result: any) => { + try { + const params = Object.assign({ + query: {}, + route: {}, + connection + }, connection); + + assert.ok(!error); + assert.deepStrictEqual(result, Object.assign({ params }, data)); + done(); + } catch (e) { + done(e); + } + }); + }); + it('.get without params', done => { const socket = new EventEmitter();