[英]firebase signInWithEmailAndPassword not working in safari
當我使用 function signInWithEmailAndPassword(email, password) 時,這在 Chrome 上完全可以正常工作。 但是,當我 go 訪問同一網站並在 iOS Safari 上使用相同的憑據時,我收到此錯誤:
code: "auth/network-request-failed", message: "發生了網絡錯誤(如超時、連接中斷或主機無法訪問)。
這是問題所在的 function。 它是從 html 表單的 onSubmit 屬性調用的。
function formSubmit() {
var config = {
// config here
};
var app = firebase.initializeApp(config);
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
console.log("firebase user is: " + firebase.auth().currentUser.uid);
return true;
} else {
console.log("No user")
}
});
var email = document.getElementById("emailInput").value;
var password = document.getElementById("passwordInput").value;
firebase.auth().signInWithEmailAndPassword(email, password)
.then(function(userReturn) {
console.log("userReturn is " + userReturn);
})
.catch(function(error) {
console.log(error);
})
}
您正在 formSubmit 處理程序中執行大量操作。 這可能會導致超時。
最好全局初始化 firebase 應用程序。
在您的.js
文件中:
// init firebase globally
var config = {
// config here
};
var app = firebase.initializeApp(config);
// this will trigger as soon as an auth state change operation happens
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
console.log("firebase user is: " + firebase.auth().currentUser.uid);
return true;
} else {
console.log("No user")
}
});
// sign users in with the formSubmit handler
function formSubmit() {
var email = document.getElementById("emailInput").value;
var password = document.getElementById("passwordInput").value;
firebase.auth().signInWithEmailAndPassword(email, password)
.then(function(userReturn) {
console.log("userReturn is " + userReturn);
})
.catch(function(error) {
console.log(error);
})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.