feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
14.97k stars 742 forks source link

Logging in with a custom auth strategy results in undefined user in connection in channels.ts #3475

Open jordandenison opened 2 months ago

jordandenison commented 2 months ago

Steps to reproduce

Steps to reproduce can be found in the index.ts at this repo/branch:

https://github.com/jordandenison/feathers-local/tree/service-authentication-issues

Expected behavior

On login event in channels.ts, connection object should have the user data returned from the custom service

Actual behavior

Connection object user is undefined

System configuration

Module versions (especially the part that's not working):

NodeJS version: 20.9

Operating System: alpine

hungrymike commented 1 month ago

There are definitely some breaking changes from v4 -> v5 regarding this, we've been dealing with something similar - since we also have custom auth on most of our projects. When you set "entity": null in the config, the connection will have null: undefined, doesn't matter if you return user or entity.

There is a quick fix for it, on app.on('login') event you'll have access to the auth result so you can add it to the connection manually, ex connection.user = authenticationResult.authentication.payload.user; That would be line 7 in your channels.ts.

Hope that helps