Account.createUser回拨不在meteorjs工作

我正在开发一个meteorjs的应用程序。 我创build了一个用于创build用户的meteor方法。 它显示了以下错误:

服务器上不支持回叫的帐号。创build用户。

这是我的meteor法

我怎样才能在account.createUser中添加callback?

Meteor.startup(function () { Meteor.methods({ postForm:function(doc){ var result = Accounts.createUser({ username: doc.username, password: doc.password, email: doc.emails, profile: { lastname: doc.lastname, contact:doc.phoneNumber, bdat:doc.bod, address:doc.address } },function(){ console.log('hello'); }); } }); }); 

错误信息中的“尚未”可能是作者的错误。 根据文件 :

在服务器上,[ Accounts.createUser ]返回新创build的用户标识。

这意味着在服务器端, Accounts.createUser本质上是阻塞的:它等待用户被创build,然后返回其新生成的ID。 所以“callback”,在这种情况下,基本上是跟随你的createUser语句的任何东西。 您将得到一个值,用户的_id,您可以使用它来使用Meteor.users.find()检索插入的用户。 如果你想覆盖错误,你可以捕获抛出的exception。

但是正如David Weldon所说,你可以在客户端上使用Accounts.createUser()来完成这个工作。 我想这是有道理的,如果你想做一些特定于服务器的“callback”创build,但也有人可能会争辩说,你可以做一个服务器方法调用只是为了。 (尽pipe在这种情况下它会调用服务器两次,一次用于创build,一次用于callback逻辑)

我收到了完全相同的错误消息,包括单词“还没有”。 我的完整的错误信息: Exception while invoking method Error: Accounts.createUser with callback not supported on the server yet. 将该错误消息翻译为

嘿,开发人员,你是个大笨蛋,你的方法调用不能通过callback处理响应和错误。 请修复您的代码。

这个问题对我来说是双重的。 像你一样,我没有充分考虑callback错误和回应。 这意味着,如果在调用链的其他地方出现错误,那么错误就不会传回给你,所以你不知道什么是错的。 先修复回拨代码。

 Meteor.methods({ postForm:function(doc){ try { var result = Accounts.createUser({ username: doc.username, password: doc.password, email: doc.emails, profile: { lastname: doc.lastname, contact:doc.phoneNumber, bdat:doc.bod, address:doc.address } }); if(result){ // are you using roles? // Roles.addUsersToRoles(result, doc.roles); return result; } } catch(err){ return err; } } }); 

希望这将'修复' callback not supported错误消息。 在那个时候,你应该能够看到真正的麻烦。 在我的情况下,这是一个错误的Accounts.validateNewUser((user)例程,我从教程中复制,忘记更新以匹配我的数据。

哦,差点忘了…这里是示例代码来调用从客户端的方法。

 Meteor.call('postForm', newUser, function(error, response) { if (error) { console.log('postForm: Error: ', error); } if (response) { console.log('postForm: Response: ', response); } }); 

祝你好运。 这里提供的信息,如果有人得到“尚未”的错误!