@moscomaster wrote:
I am building Ionic app and using firebase. I have a problem when I want to check verification email when user login.
I tested login with Email that not verified yet and alert "Email not verified please check your inbox" show normally but it's login and go to state "tab.dashB" too.
I think it's because "//Check if user already logged in". so I try to make a condition but it didn't work.
can someone teach me how to slove this problem please? (T_T)
ps.other error checking run normally.
this is code
.controller('loginCtrl', function($scope,$ionicHistory,TheAlert,$state) { var condition = true; $scope.loginEmail = function(formCheck,userLogin) { console.log(userLogin); if(formCheck.$valid) { // Check if the form data is valid or not // Start showing the progress TheAlert.showLoading(); firebase.auth().signInWithEmailAndPassword(userLogin.email,userLogin.password).then(function() { var user = firebase.auth().currentUser; if(user.emailVerified) { //check for verification email console.log("email verified"); $ionicHistory.nextViewOptions({ historyRoot: true }); TheAlert.hideLoading(); $state.go('tab.dashB', {}, {location: "replace"}); }else{ condition = false; TheAlert.hideLoading(); TheAlert.showAlert("Email not verified please check your inbox","","warning") return false; } // end check verification email },function(error) { var errorCode = error.code; var errorMessage = error.message; console.log(errorCode); if (errorCode === 'auth/invalid-email') { TheAlert.showAlert("Invalid Email","","error"); TheAlert.hideLoading(); return false; }else if (errorCode === 'auth/wrong-password') { TheAlert.showAlert("Password is incorrect","","error"); TheAlert.hideLoading(); return false; }else if (errorCode === 'auth/user-not-found') { TheAlert.showAlert("Account\ndoes not exist","","error"); TheAlert.hideLoading(); return false; }else if (errorCode === 'auth/too-many-requests') { TheAlert.showAlert("Too many failed login attempts please try after some delay","","error"); TheAlert.hideLoading(); return false; }else if (errorCode === 'auth/network-request-failed') { TheAlert.showAlert("Request timed out please try again","","error"); TheAlert.hideLoading(); return false; }else if (errorCode === 'auth/user-disabled') { TheAlert.showAlert("This account has been disabled by Admin","","error"); TheAlert.hideLoading(); return false; }else { TheAlert.showAlert(errorMessage,"","error"); TheAlert.hideLoading(); return false; } } ); }else{TheAlert.showAlert("Please fill all details","","warning"); return false;} }; if(condition == true){ //Check if user already logged in firebase.auth().onAuthStateChanged(function(user) { if (user) { $ionicHistory.nextViewOptions({ historyRoot: true }); $state.go('tab.dashB', {}, {location: "replace"}); } }); };
Posts: 1
Participants: 1