v5 AuthenticationService create hooks reversed order
I recently began updating a feathers v4 app to v5 in anticipation of it's release. So far the upgrade has been pretty smooth! the one issue I ran into and believe is a bug is how the AuthenticationService class sets up it's hooks
V5
https://github.com/feathersjs/feathers/blob/4ff1ed084eb2b2cb687de27a28c96a0dad4530b7/packages/authentication/src/service.ts#L45
V4 https://github.com/feathersjs/feathers/blob/d0e9600002975296ab8de926acd317d0a73fce5c/packages/authentication/src/service.ts#L172
It looks like in V5 these are now using @feathersjs/hooks directly and appear to run in reverse order
basically what appears to happen is the app.login event is emitted before the user entity is added to connection object. this means the "user" will never get assigned to the authenticated clients channel
Expected behavior
the user object should be available on the connection object in the app.login event handler
Actual behavior
user is not available on the connection object in the app.login event handler. so it is never added to the "authenticated" channel.
System configuration
Module versions (especially the part that's not working): 5.0.0-pre.33
NodeJS version: v17.2.0
Operating System: arch linux
Browser Version:
React Native Version:
Module Loader:
Was this a problem you you were able to confirm? The order should be correct, because around hooks are functions that wrap around each other so the statements after await next() in around hooks run in the reverse order as traditional after hooks would. The following
service.hooks({
around: {
all: [
async (context, next) => {
await next() // This will call and run _all_ of the next hook
console.log('First')
},
async (context, next) => {
await next()
console.log('Second')
}
]
}
})
Will print Second and then First.
Oh sorry, my bad, I get it now. The order should be reversed because of what I just explained but they are still in the same order which is causing the problem you are describing.
yes exactly! I think it needs to be swapped so that it works the same way as it did in V4. Locally I patched it to reverse the order of those hooks and it worked as expected, like in v4. I was able to access the user again in the login event.