我正在重寫我的網站,將JavaScript與Firebase結合使用。到目前爲止,我喜歡Firebase,但現在我需要將所有舊用戶遷移到Firebase系統。Firebase身份驗證 - 將用戶從SQL遷移到Firebase
所有的用戶都有自定義的額外設置,我不想把服務器放在現在的位置(€103,p/m)。所以我需要全部複製。據我所知,它需要逐一完成(createUserWithEmailAndPassword
)。在服務器上,我做一個JSON對象,並在新的網站,我做的事:
$.get("/alljsonfromalink", function (rdata) {
var $jData = jQuery.parseJSON(rdata);
var i = 0;
for (var user in $jData) {
whenYouFeelLikIt(user, $jData);
}
});
function whenYouFeelLikIt(i, $jData) {
setTimeout(function() {
firebase.auth().signInWithEmailAndPassword($jData[i].email, RandomPassword)
.then(function(){
console.log("Succes Login");
//if exist i set extra settings
setusersettings($jData[i], $jData[i].email);
})
.catch(function(error) {
var errorCode = error.code;
console.log(errorCode);
if(errorCode == "auth/user-not-found") {
firebase.auth().createUserWithEmailAndPassword($jData[i].email, RandomPassword).then(function() {
console.log("Created: " + $jData[i].email);
});
}
});
},2000 * (i));
}
它的工作原理,但即使有一個2秒超時,我經過20點或30的插入了:
firebase.js:73 Uncaught Error: We have blocked all requests from this device due to unusual activity. Try again later.
任何人都有一個想法如何解決這個問題?
--Update--
JamieB建議使用.fetchProvidersForEmail()所以現在我用
firebase.auth().fetchProvidersForEmail($jData[i].email)
.then(function(succes){
console.log(succes.length);
if(succes.length == 0) {
// the createUserWithEmailAndPassword() with timeout
create(i, $jData);
}
})
也許你可以嘗試使用https://firebase.google.com/docs/reference/js/firebase.auth .Auth#fetchProvidersForEmail而不是以檢查用戶是否存在的方式登錄? 我無法測試這個,但看着API,看起來像一種方式來確定一個用戶是否存在沒有自動化。 – JamieB
謝謝,它有點幫助。現在我可以創建更多的用戶,但是仍然在X插入後我被阻止。 – user1664803
您是否需要預先創建所有用戶?你不能在他們第一次訪問你的網站時在Firebase中創建它們嗎?或者:你可以嘗試從'createUserWithEmailAndPassword()'開始,它可能有不同/更高的速率限制。 –