Twitter或普通帐户用户名冲突-Meteor
用户可以使用电子邮件或twitter创建帐户。下面代码的问题是,它不允许具有正常帐户的用户创建帖子Twitter或普通帐户用户名冲突-Meteor,meteor,meteor-accounts,Meteor,Meteor Accounts,用户可以使用电子邮件或twitter创建帐户。下面代码的问题是,它不允许具有正常帐户的用户创建帖子 Posts.insert({ text: text, createdAt: new Date(), owner: Meteor.userId(), username: Meteor.user().username, twitname: Meteor.user().profile.name, upvoters: [],
Posts.insert({
text: text,
createdAt: new Date(),
owner: Meteor.userId(),
username: Meteor.user().username,
twitname: Meteor.user().profile.name,
upvoters: [],
votes: 0,
commenters: [],
comments: 0,
});
如果我抹掉
twitname: Meteor.user().profile.name,
这两个帐户都可以再次创建帖子,但它不会显示由twitter帐户创建的帖子的用户名。我找到了一个解决方案。希望这对别人有帮助 我们所做的是告诉“用户名”从下面这样的一个或另一个获取数据 在服务器内部,Meteor.methods:
username: function(){
return Meteor.user().username || Meteor.user().profile.name
}
以及我们的插入方法:
Posts.insert({
text: text,
createdAt: new Date(),
owner: this.userId,
username: Meteor.user().username,
});
内部HTML:
{{username}}
PS:我已经安装了谷歌、推特和FB的登录。上述解决方案适用于所有这些问题
编辑:
我发现使用onCreateUser更好
例如:
Accounts.onCreateUser(function(options,user){
if (typeof(user.services.facebook) != "undefined") {
username: user.services.facebook.name;
}
if (typeof(user.services.google) != "undefined") {
user.username = user.services.google.name;
}
//etc.
})
这样,您就不必检查哪个服务,也不必编写任何其他内容,因为所有服务都是“用户名”。您只需将正确的数据插入同一位置