setup authentication using feather-client(socket.io) and add login event to feather api-server(setup feather server using feather express and socket modules).
when the user authenticates from UI, feather emits the login event twice for the same user.
it should emit one login event when the same user authenticates from UI.
when user login through app feather server emits login event twice for the same user.
Tell us about the applicable parts of your setup.
Module versions (especially the part that's not working):
feather server:
"@feathersjs/authentication": "2.1.6",
"@feathersjs/authentication-jwt": "2.0.1",
"@feathersjs/authentication-local": "1.2.1",
"@feathersjs/configuration": "1.0.2",
"@feathersjs/express": "1.2.2",
"@feathersjs/feathers": "3.2.3",
"@feathersjs/socketio": "3.2.1"
feather-client:
"@feathersjs/[email protected]"
NodeJS version:
8.9.3
Operating System:
host: Ubuntu 16.04.5 LTS (x86_64)
container image: alpine:3.7
I know feather socket.io uses pooling transport first after that then it upgrades to web socket transport.
so is there any to prevent the double login event?
your help will be appreciated.
This is a confirmed bug, originally reported in https://github.com/feathersjs/authentication/issues/673. Keeping this one open to track things here.
@daffl ,
I noticed that this happens because of socket transport upgrade from polling to websocket that's when you will see two login events.
another thing i noticed that if i run feathers server and client locally than i don't see two login event i.e in same local network; if i put client and server apart via internet than only i see two login events that's may be because of network latency.
I figured two possible workaround for this to prevent two login events.
I've right now used transport in revers order i.e. fallback approach; so i'm not getting two login events.
I know this is temporary fix ideally socket should prevent that OR it should fire two logout in conjunction to that
Could this be related to why I keep getting an error of app.emit is not a function
when users attempt to login?
Thanks for digging into this @vinaykharecha. I'll verify that this is no longer happening for Authentication v3 (https://github.com/feathersjs/feathers/issues/1045)
@daffl ,
I noticed that this happens because of socket transport upgrade from polling to websocket that's when you will see two login events.
another thing i noticed that if i run feathers server and client locally than i don't see two login event i.e in same local network; if i put client and server apart via internet than only i see two login events that's may be because of network latency.
I figured two possible workaround for this to prevent two login events.
- In feathers client if you configure socket with upgrade false than you will not see two login events
- Or if you put configure transport in this order than also you will not see two login events transports: [ 'websocket','polling']
I've right now used transport in revers order i.e. fallback approach; so i'm not getting two login events.
I know this is temporary fix ideally socket should prevent that OR it should fire two logout in conjunction to that
@vinaykharecha where you changed order of transports? Thanks!
@matiaslopezd ,
Order of transports needs to be changed on client side not server side.
On client side code where you are configuring socket io at that time you need to pass option.
Following is example snippet; in that replace "https://feathers.domain.com" with your feathers server url
const feathers = require('@feathersjs/feathers');
const socketio = require('@feathersjs/socketio-client');
const io = require('socket.io-client');
const app = feathers();
const socket = io("https://feathers.domain.com", {
transports: ['websocket','polling'],
forceNew: true
});
app.configure(socketio(socket));
@vinaykharecha thanks you! :smile:
Closing since this should no longer be happening in Feathers v4 authentication. See the Migration guide for more information on how to upgrade.
@daffl new version? :scream:
I have this problem again and I use v4.
my config:
"@feathersjs/authentication-client": "^4.5.1",
"@feathersjs/feathers": "^4.5.1",
"@feathersjs/socketio-client": "^4.3.11",
Results of connection:
Authentication successful for: xyz // console.log from authenticate
New connection request. event is: login // from handleConnection
Adding authentication information to connection: xyz // from handleConnection
New connection request. event is: login
Adding authentication information to connection: xyz
Anonymous connection request // from channels, app.on('connection',.... but the connection is known
User xyz has joined 6 channels // from channels, app.on('login',.....
User xyz @vhci.ro has joined 6 channels
Most helpful comment
@matiaslopezd ,
Order of transports needs to be changed on client side not server side.
On client side code where you are configuring socket io at that time you need to pass option.
Following is example snippet; in that replace "https://feathers.domain.com" with your feathers server url