Skip to content

Commit

Permalink
fix(authentication): Fix order of connection and login event handling (
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Dec 8, 2022
1 parent 142914f commit 801a503
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/authentication/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
27 changes: 27 additions & 0 deletions packages/authentication/test/jwt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 801a503

Please sign in to comment.