【问题标题】:accounts-meld not working帐户融合不起作用
【发布时间】:2014-06-24 16:29:06
【问题描述】:

Accounts-meld 不适合我,它应该解决问题还是我需要做点什么?我正在滚动我自己的 ui 并为 Facebook 和 Twitter 使用 Meteor.loginWithXX()。我曾尝试手动创建一个帐户,然后使用第三方登录,但它只是创建一个新用户并且不会合并它们。

我做错了吗?

我正在使用

配置我的服务
Accounts.loginServiceConfiguration.insert({
    "service": "facebook",
    "appId": "XXXXXXXXXXXX",
    "secret": "XXXXXXXXXXXX"
});

Accounts.loginServiceConfiguration.insert({
    "service": "twitter",
    "consumerKey": "XXXXXXXXXXXX",
    "secret": "XXXXXXXXXXXX"
});

然后我使用 Meteor.loginWithFacebook();和 Meteor.loginWithTwitter();

任何帮助将不胜感激

【问题讨论】:

    标签: javascript jquery meteor


    【解决方案1】:

    让我发布我正在使用的代码,如果它有帮助,您可以告诉我。这不是我的代码,是从其他答案中发现的,但我无法提供来源。

    您有权使用服务配置来设置每个服务,但如果您还没有安装该软件包,则需要安装该软件包。

    然后,我为我提供的每个登录服务添加了一个类似这样的事件。

    Template.login.events({
      "click #loginWithFacebook": function (event) {
        event.preventDefault();
        Meteor.loginWithFacebook({
    
        }, function(error) {
          if (error) {
            console.log(error);
          }
        });
      }
    });
    

    然后我还有一个 onCreateUser 代码块,它会检查它是否是新用户,或者他们是否只是使用新服务作为他们的登录提供程序。对此进行了一些调整,因此您需要删除不相关的内容。

    Accounts.onCreateUser(function(options, user) {
      var email, oldUser, service; 
    
      if (user.profile == null) {
        user.profile = {};
        if (options.profile != null) {
          user.profile.name = options.profile.name;
          user.profile.organisation = options.profile.organisation;
        }
      }
    
      if (user.services != null) {
        service = _.keys(user.services)[0];
        email = user.services[service].email;
        if (email != null) {
          oldUser = Meteor.users.findOne({
            "emails.address": email
          });
          if (oldUser != null) {
            if (oldUser.services == null) {
              oldUser.services = {};
            }
            if (service === "google" || service === "facebook") {
              oldUser.services[service] = user.services[service];
              Meteor.users.remove(oldUser._id);
              user = oldUser;
            }
          } else {
            if (service === "google" || service === "facebook") {
              if (user.services[service].email != null) {
                user.emails = [
                  {
                    address: user.services[service].email,
                    verified: true
                  }
                ];
              } else {
                throw new Meteor.Error(500, "" + service + " account has no email attached");
              }
              user.profile.name = user.services[service].name;
              user.profile.organisation = Organisations.find({}, {'fields': {'_id':1}}).fetch()[0];
            }
          }
        }
      }
      return user;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多