如何使用firebase Auth检索和处理重定向错误?

时间:2016-09-10 07:42:37

标签: javascript firebase firebase-authentication facebook-authentication google-authentication

我正在使用Firebase Auth开发移动优先应用。 Firebase建议重定向而不是弹出窗口。但是,我似乎无法找到任何使用Oauth提供程序(Facebook,Google)检索错误的示例。 Firebase在SignwithPopup中有一个处理错误的示例,但在重定向之前它只声明:

  

此错误在重定向模式下以类似的方式处理   必须在页面之间缓存挂起的凭证的区别   重定向(例如,使用会话存储)。

1 个答案:

答案 0 :(得分:3)

我们在同一个文档的上一部分中显示了重定向操作的错误处理位置:只需搜索" firebase.auth()。getRedirectResult()" this page特别是catch这里:

firebase.auth().getRedirectResult().then(function(result) {
  if (result.credential) {
    // This gives you a Google Access Token. You can use it to access the Google API.
    var token = result.credential.accessToken;
    // ...
  }
  // The signed-in user info.
  var user = result.user;
}).catch(function(error) {
  // Handle Errors here.
  var errorCode = error.code;
  var errorMessage = error.message;
  // The email of the user's account used.
  var email = error.email;
  // The firebase.auth.AuthCredential type that was used.
  var credential = error.credential;
  // ...
});

顺便说一句,添加多个身份验证提供程序并完美地处理链接帐户实际上非常棘手,因为需要考虑许多子流(例如,如果用户想要链接但是然后登录电子邮件的帐户,该怎么办?不符合...)。我建议你使用Firebase UI,它提供了一个可配置的UI组件,可以为你处理所有这些棘手的流程。

相关问题