【问题标题】:AngularFire should a provider's uid be the same as an anonymous user's uid after they are linked?AngularFire 在链接后提供者的 uid 是否应该与匿名用户的 uid 相同?
【发布时间】:2016-12-13 01:12:38
【问题描述】:

我正在尝试将提供商链接到匿名用户。我可以分别登录。

var auth = $firebaseAuth();
auth.$signInAnonymously().then(function(firebaseUser) {...}

$scope.signInWithGoogle = function() {
var provider = new firebase.auth.GoogleAuthProvider();

  auth.$signInWithPopup(provider)
    .then(function(response) {
      linkCredentials(response.user);
    }).catch(function(error) {
      console.error("Authententication failed:", error);
    });
}

var linkCredentials = function(credential) {
  if(credential) {
    var credentials = credential;
  }

  firebase.auth().currentUser.link(credentials)
    .then(function(firebaseUser) {
        console.log("Anonymous account successfully upgraded", firebaseUser);
    }).catch(function(error) {
        console.log("Error upgrading anonymous account", error);
    });
}

当我使用电子邮件和密码(即$createUserWithEmailAndPassword)关联帐户时,新创建的帐户的uid 与匿名帐户相同。

Google 用户的 uid 是否应该与关联后的匿名帐户相同?还是我在这里混淆了事情?提前感谢您的帮助。

【问题讨论】:

    标签: angularjs firebase firebase-authentication angularfire


    【解决方案1】:

    当您将新提供者链接到现有帐户时,无论该帐户是否匿名,都应保持相同的 uid。但是,如果您尝试将已链接到具有不同 uid 的现有 firebase 用户的提供程序链接,您将收到凭据已链接到另一个帐户的错误消息。您似乎在上面做错了。在匿名用户登录后,您正在登录谷歌用户,有效地注销了以前的匿名用户。正确的做法如下:

    您首先匿名登录。

    然后对当前匿名用户调用 linkWithPopup。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-24
    • 1970-01-01
    • 2018-02-10
    • 1970-01-01
    • 2010-10-29
    相关资源
    最近更新 更多