I have an issue where, when I log a JavaScript object (a subscription handler) in Meteor I am able to see the field 0
but I am unable to retrieve it from the code.
I am using numtel:mysql
package.
Here is the entire Meteor code used to reproduce the issue:
Bootstrap
Meteor.startup(function() {
Meteor.readLiveDb = new LiveMysql(Meteor.Config.mysql.read);
Meteor.writeLiveDb = new LiveMysql(Meteor.Config.mysql.write);
var closeAndExit = function() {
Meteor.readLiveDb.end();
Meteor.writeLiveDb.end();
process.exit();
};
// Close connections on hot code push
process.on('SIGTERM', closeAndExit);
// Close connections on exit (ctrl + c)
process.on('SIGINT', closeAndExit);
});
Publish Code
Meteor.publish("checkLoginSubscription", function(username, password) {
if(typeof username === undefined || typeof password === undefined) {
throw new error('Username or password cannot be blank');
return;
}
var user = Meteor.readLiveDb.select(
'select * from users where username = "' + username + '" and password = "' + password + '"', [{
table: 'users'
}]
);
return user;
});
Event Code
Template.login.events({
'submit #loginform': function(event) {
event.preventDefault();
$('#message').fadeIn();
var username = event.target.username.value;
var password = CryptoJS.MD5(event.target.password.value).toString();
console.log('The Password entered is ', password);
if(username == '' || password == '') {
$('#message').addClass('alert-danger').removeClass('alert-success');
$('#message').html('Username or password cannot be blank');
return;
}
$('#message')
.html('<img src="img/loaders/1.gif" alt="loading" /> Logging you in...')
.addClass('alert-success')
.removeClass('alert-danger');
var cLogin = new MysqlSubscription('checkLoginSubscription', username, password);
console.log(cLogin); // This is the variable holding the object
console.log(cLogin[0]); //undefined!
}
});
On the last line you can see the log:
console.log(cLogin);
When I try to get the 0: Object
part of the handler it returns undefined
.
What is going wrong? How can I access this data?