2016-02-25 64 views
0

此代碼嘗試向流星用戶中已有的用戶添加字段。
我得到的錯誤是創建後向用戶添加字段

Exception while invoking method 'logMeIn' Error: insert requires an argument

,我不明白,怎麼能解決嗎?由於

///////////////////////////////////// 
//  client code 
///////////////////////////////////// 
Template.login.events({ 
    'click #logMe': function() { 
    var username = $('#id').val(); 
    var password = $('#pin').val(); 
    Meteor.call('logMeIn', [username,password], function (err, data) { //create new user 
     if (err) { 
     if (err.message.match(/username already exists/i)) { 
      Meteor.loginWithPassword(username+password,password) 
     } 
     } else { 
     console.log('new user created'); 
     } 
    }); 
    } 
}); 

///////////////////////////////////// 
//  server code 
///////////////////////////////////// 

Meteor.methods({ 
    logMeIn: function (credentials) { 
    //do work , if logged in, do next line 
    var idPin = credentials[0] + credentials[1]; 
    Accounts.createUser({username: idPin, password: credentials[1]}); 
    } 
}); 


Accounts.onCreateUser(function (options, user) { 
    user.menuGroup = 'a'; 
}); 

回答

0

您需要在Account.onCreatedUser(文檔here)返回user。此外,用戶的附加數據應該在profile分支(檢查here的文檔)

Accounts.onCreateUser(function (options, user) { 
    if (options.profile) { 
     user.profile = options.profile; 
    } 

    if (user['profile'] == null) { 
     user['profile'] = {}; 
    } 

    user['profile']['menuGroup'] = 'a'; 
    return user; 
}); 
+0

給出下予以糾正; TypeError:無法設置屬性'menuGroup'的undefined –

+0

我更新了我的答案 –

相關問題