2017-08-25 1 views
0

私は、指定された電子メールとパスワードのリストを使って、firebaseにループ(JS)経由で100人のユーザを登録しようとしています。例外をスキップするFirebase Javascript

しかし、それらのうちのいくつかは既に存在しており、電子メールのフォーマットが悪いものはほとんどありません。だからユーザの電子メールが既に登録されているか、またはひどくフォーマットされている場合は、というスクリプトが例外をスローします。そのユーザーの登録をスキップして、次のユーザーに続けます。

例外が発生した場合にループをスキップする方法。

for (var i = 0; i < data.length; i++){ 
//Variables of email and password 
if (email !== '' && email !== undefined) { 
     const promise = firebase.auth().createUserWithEmailAndPassword(email, password) 
     .then(function(response) { 
      console.log(response.uid); 
    }); 
    promise.catch(function(e){ 
     console.log(e.message); 
     //Skip and continue to next iteration 
    }); 
    } 
} 

答えて

0

あなたはPromise.allを使用することができます。

var promises = []; 
for (var i = 0; i < data.length; i++) { 
    promises.push(firebase.auth().createUserWithEmailAndPassword(email, password) 
    .then(function(userRecord) { 
    }).catch(function(error) { 
     console.log(error). 
    })); 
} 
Promise.all(promises).then(function() { 
    console.log('done'); 
}); 
関連する問題