0

Using this vue.js method to login users:

   loginUser: function () {
        socket.emit('loginUser', {
            email: this.email ,
            password: this.password         
        }, function() {
            console.log('rooms in callback are:', rooms);
        });
    }

On the server the loginUser event is handled by:

socket.on('loginUser', (newuser,callback)=> {
  var body = _.pick(newuser, ['email', 'password']);
  console.log('body is:', body);
      User.findByCredentials(body.email, body.password).then((user) => {
        return user.generateAuthToken().then((token) => {

           if (token) {
                    console.log('token was found');
                     let rooms = ['Cats', 'Dogs', 'Birds'];
                    callback(rooms);

            } else {
               socket.emit('loginFailure', {'msg' : 'Login failure'});
            }
        }).catch((e) => {
          throw e;
        });
      }).catch((e) => {
           socket.emit('loginFailure', {'msg' : 'Login failure'});
           throw e;

      });
});

I can see 'token was found' printed out in the console but does not recieve the rooms being printed in the browser console. I receive no errors either.

I'm wondering whetehr it is due to how vue.js methods work? And if so, if there is a way around it?

1 Answer 1

1

You forgot to specify rooms as argument in the callback

loginUser: function () {
        socket.emit('loginUser', {
            email: this.email ,
            password: this.password         
        }, function(rooms) { // need to have rooms argument
            console.log('rooms in callback are:', rooms);
        });
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.