Meteor用户属性未定义

时间:2015-04-30 18:39:24

标签: javascript mongodb meteor

用户waitOn数据订阅:

waitOn: function(){
    if(Meteor.user()){
        var current_user_admin_status = Meteor.user().admin;
        console.log(current_user_admin_status);
        return Meteor.subscribe('users', current_user_admin_status);
    }
}

current_user_admin_status始终返回null,即使我可以进入数据库并找到admin字段

db.users.find({"_id" : "6Mqx5Ky92bZfhaX8A"}, {"admin" : 1})

  

{" _id" :" 6Mqx5Ky92bZfhaX8A"," admin" :true}

我在客户端上定义此变量,如果当前用户是管理员,则传递给服务器以仅发布用户集合,但它仍然被null if else语句抓住

Meteor.publish('users', function(current_user_admin_status){
    if(!this.userId){
        console.log('you are not signed in');
    }
    else if( current_user_admin_status = 'null' ){
        console.log('you are not an admin');

    } else if ( current_user_admin_status = 'false' ) {
        console.log('you are not an admin');

    } else if (current_user_admin_status = 'undefined'){
        console.log('you are not an admi');

    } else {
        console.log('you are logged in as an admin');
        return Meteor.users.find({}, {fields: {createdAt: 1, admin: 1, emails: 1, username: 1, first_name: 1, last_name: 1}}); 
    }
});

0 个答案:

没有答案