Passport.socketio - 2 users connect for every 1 connection

Passport.socketio - 2 users connect for every 1 connection

Full code:!/fcc-socketio-auth

I implemented the option to pass ‘success’ and ‘fail’ with a function that’s called after the authentication process completes when a client tries to connect.

But now my browser console log 'user count' is incremented twice for each time I connect via the ‘Login with Github’ link.

When passportSocketIo reads the user cookie and runs either onAuthorizeSuccess or onAuthorizeFail is that registered as a connection (user) also?

// Authentication with Socket.IO
      cookieParser: cookieParser,
      key:          'express.sid',
      secret:       process.env.SESSION_SECRET,
      store:        sessionStore,
      success:      onAuthorizeSuccess,   
      fail:         onAuthorizeFail,  
// listening for connections
    var currentUsers = 0;  
    io.on('connection', socket => {
      console.log('A user has connected');
      io.emit('user count', currentUsers);
      console.log('user ' + + ' connected');
      socket.on('disconnect', () => { 
        console.log('a user has disconnected');
        io.emit('user count', currentUsers);