From 801a503425062e27f2a32b91493b6ffae3822626 Mon Sep 17 00:00:00 2001 From: David Luecke Date: Thu, 8 Dec 2022 13:37:02 -0800 Subject: [PATCH] fix(authentication): Fix order of connection and login event handling (#2909) --- packages/authentication/src/service.ts | 4 ++-- packages/authentication/test/jwt.test.ts | 27 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/authentication/src/service.ts b/packages/authentication/src/service.ts index f3b7107c0e..58f219143f 100644 --- a/packages/authentication/src/service.ts +++ b/packages/authentication/src/service.ts @@ -42,8 +42,8 @@ export class AuthenticationService super(app, configKey, options) hooks(this, { - create: [resolveDispatch(), connection('login'), event('login')], - remove: [resolveDispatch(), connection('logout'), event('logout')] + create: [resolveDispatch(), event('login'), connection('login')], + remove: [resolveDispatch(), event('logout'), connection('logout')] }) this.app.on('disconnect', async (connection) => { diff --git a/packages/authentication/test/jwt.test.ts b/packages/authentication/test/jwt.test.ts index 85ac9cb3d2..8120d3cb9f 100644 --- a/packages/authentication/test/jwt.test.ts +++ b/packages/authentication/test/jwt.test.ts @@ -133,6 +133,33 @@ describe('authentication/jwt', () => { }) }) + it('login event connection has authentication information (#2908)', async () => { + const connection: any = {} + const onLogin = new Promise((resolve, reject) => + app.once('login', (data, { connection }) => { + try { + assert.deepStrictEqual(connection.user, { + ...user, + isExternal: true + }) + resolve(data) + } catch (error) { + reject(error) + } + }) + ) + + await app.service('authentication').create( + { + strategy: 'jwt', + accessToken + }, + { connection, provider: 'test' } + ) + + await onLogin + }) + it('resolves safe dispatch data in authentication result', async () => { const authResult = await app.service('authentication').create({ strategy: 'jwt',