尝试创建并授权匿名执行:
Meteor.startup(function () {
// Allocate a new user id.
if (!Meteor.userId()) {
var pass = Random.create().id();
var email = pass+'@example.com';
Accounts.createUser({password: pass, email: email}, function(err){
Meteor.loginWithPassword({password: pass, email: email});
});
} else {
}
});
这几乎运作良好。但有时meteor会同时创建两个用户。 :(
答案 0 :(得分:0)
这取决于你的意思," meteor一次创造了两个用户" ...
如果您的意思是,"为什么我访问网站时会不断创建用户记录"那么因为Meteor需要一些时间来登录用户,直到该过程完成,Meteor.userId()将为null。见http://docs.meteor.com/#meteor_loggingin
如果您发布的代码实际上是第一次访问时创建了2个用户(使用干净的数据库),那么我也会感到惊讶。完整的repro将有助于调试该案例;也许你可以通过github的链接更新你的答案?