Login 使用自定义登录方法时获取服务器错误

Login 使用自定义登录方法时获取服务器错误,login,meteor,Login,Meteor,我正在尝试测试自定义登录方法功能,因此这是我的客户端: Meteor.loginWithCode = function(phone, code) { Accounts.callLoginMethod({ methodArguments: [{ hascode: true, phone: phone, code: code }], userCallback: function loginCallback (error, result

我正在尝试测试自定义登录方法功能,因此这是我的客户端:

Meteor.loginWithCode = function(phone, code) {

  Accounts.callLoginMethod({
    methodArguments: [{
      hascode: true,
      phone: phone,
      code: code
    }],
    userCallback: function loginCallback (error, result) {
      console.log(error, result);
    }
  });
};
这是服务器:

Accounts.registerLoginHandler('login', function(loginRequest) {

  var user = Meteor.users.findOne({phone: loginRequest.phone});

  if(user.code !== loginRequest.code) {
    return null;
  }

  var stampedToken = Accounts._generateStampedLoginToken();
  var hashStampedToken = Accounts._hashStampedToken(stampedToken);

  Meteor.users.update(user._id,
    {$push: {'services.resume.loginTokens': hashStampedToken}}
  );

  return {
    id: user._id,
    token: stampedToken.token
  };
});
为什么我会受伤

Exception while invoking method 'login' Error: A login method must specify a userId or an error

当我使用Meteor.loginWithCode('123456789','123')?

您应该返回
userId
而不是
id

Accounts.registerLoginHandler('login', function(loginRequest) {
  ...
  ...
  return {
    userId: user._id,
    token: stampedToken.token
  };
})
如果登录失败,则传递
错误
,而不是
用户ID

证明:

if (!result.userId && !result.error)
   throw new Error("A login method must specify a userId or an error");