Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

login event emit twice for same user using socket.io #1174

Closed
raushansingh629 opened this issue Jan 18, 2019 · 10 comments
Closed

login event emit twice for same user using socket.io #1174

raushansingh629 opened this issue Jan 18, 2019 · 10 comments

Comments

@raushansingh629
Copy link

Steps to reproduce

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.

Expected behavior

it should emit one login event when the same user authenticates from UI.

Actual behavior

when user login through app feather server emits login event twice for the same user.

System configuration

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/client@3.7.6"
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.

@raushansingh629 raushansingh629 changed the title login event emmit two times using feather socket.io login event emmit twice for same user using feather socket.io Jan 18, 2019
@daffl
Copy link
Member

daffl commented Jan 18, 2019

This is a confirmed bug, originally reported in feathersjs-ecosystem/authentication#673. Keeping this one open to track things here.

@vinayk047
Copy link

@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.

  1. In feathers client if you configure socket with upgrade false than you will not see two login events
  2. 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

@dottodot
Copy link

Could this be related to why I keep getting an error of app.emit is not a function when users attempt to login?

@daffl daffl changed the title login event emmit twice for same user using feather socket.io login event emit twice for same user using socket.io Jan 25, 2019
@daffl
Copy link
Member

daffl commented Feb 7, 2019

Thanks for digging into this @vinaykharecha. I'll verify that this is no longer happening for Authentication v3 (#1045)

@daffl daffl closed this as completed Feb 7, 2019
@daffl daffl reopened this Feb 7, 2019
@matiaslopezd
Copy link

@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.

  1. In feathers client if you configure socket with upgrade false than you will not see two login events
  2. 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!

@vinayk047
Copy link

@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));

@matiaslopezd
Copy link

@vinaykharecha thanks you! 😄

@daffl
Copy link
Member

daffl commented Jun 6, 2019

Closing since this should no longer be happening in Feathers v4 authentication. See the Migration guide for more information on how to upgrade.

@daffl daffl closed this as completed Jun 6, 2019
@matiaslopezd
Copy link

@daffl new version? 😱

@SharpBCD
Copy link

SharpBCD commented Feb 27, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants