我正在开发移动第一应用程序,使用Firebase Auth。Firebase建议重定向而不是弹出。然而,我似乎找不到在使用Oauth提供者(facebook、Google)时检索错误的任何例子。Firebase有一个在SignwithPopup中处理错误的例子,但在重定向之前,它只声明:
此错误在重定向模式下以类似的方式处理,不同之处在于页面重定向之间必须缓存挂起的凭据(例如,使用会话存储)。
发布于 2016-09-10 17:22:09
我们在同一文档的前一节中展示了在何处执行重定向操作的错误处理:只需在firebase.auth().getRedirectResult()中搜索此页中的“catch ()”,特别是在这里的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;
// ...
});顺便说一下,添加多个auth提供者并完美地处理链接帐户实际上是相当棘手的,因为有许多子流需要考虑(例如,如果用户希望链接但随后签名--在电子邮件不匹配的帐户中.)。我建议您使用Firebase用户界面,它提供了一个可配置的UI组件,它将为您处理所有这些棘手的流。
https://stackoverflow.com/questions/39423831
复制相似问题