This is my code for my onCreateUser. All I want to do is just have a score variable attached to the player. When I try to access it in the client using
Meteor.user().score
or
Meteor.user().profile['score']
both return undefined. If there is a better way to accomplish what I am trying to do? Because right now this is really pissing me off on how it is doing nothing. I am using accounts-password and ian:accounts-ui-bootstrap-3 (alternative to accounts-ui for bootstrap).
if (Meteor.isClient) {
Accounts.ui.config({
passwordSignupFields: 'USERNAME_ONLY'
});
Meteor.subscribe('userData');
Template.leaderboard.helpers({
players: function() {
if (Meteor.user()) {
console.log(Meteor.user().score);
return Meteor.users.find({}, {sort: {'score': -1}});
}
}
})
}
if (Meteor.isServer) {
Accounts.onCreateUser(function(options, user) {
user.score = 0;
if (options.profile) {
user.profile = options.profile;
}
return user;
})
Meteor.publish("userData", function () {
return Meteor.users.find({}, {sort: {'score': -1}});
});
Meteor.startup(function () {
// code to run on server at startup
});
}
Meteor.methods({
});
There’s the whole file; it is being called from the server. Just putting the whole thing just in case. (Sorry for poor indents, ctrlc ctrlv messed it up)
The console.log in the leaderboard helper says undefined. And the field is non-existant in MongoDB I think that maybe the account-ui is handling this function for me so it is getting ignored here.