Firebase Authentication JavaScript get success

后端 未结 3 1847
清酒与你
清酒与你 2020-12-19 08:29

With the following Firebase email authentication code, how do you know whether authentication was successful?

firebase.auth().signInWithEmailAndPassword(emai         


        
3条回答
  •  一整个雨季
    2020-12-19 08:30

    If nothing was cached then it was successful.

    var isSuccessful = true
    firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
            // Handle Errors here.
            var isSuccessful = false
            var errorCode = error.code;
            var errorMessage = error.message;
    
            if (errorCode === 'auth/wrong-password') {
              alert('Wrong password.');
            } else {
              alert(errorMessage);         
            }
    
            console.log(error);
        })
        finally {
         if(isSuccessful)
             //Success!
        }
    

提交回复
热议问题