Javascript firebase.auth (). signInWithEmailAndPassword will not be able to receive a success event

I am working with java-script fire-base in my application.

I successfully createUserWithEmailAndPassword in the application. It also shows that the data is inside the Fire-base Console .

Here is a snippet.

 firebase.auth().createUserWithEmailAndPassword(" abc@gmail.com ", "*******").catch(function(error) { // Handle Errors here. var errorCode = error.code; var errorMessage = error.message; console.log("Eroor Msg" + errorMessage); // ... }); 

Then I went through firebase.auth().signInWithEmailAndPassword .

Using the above method, I cannot get any successful event or message for log . Even he does not throw any error .

Here is a snippet.

 firebase.auth().signInWithEmailAndPassword(" abc@gmail.com ", "*****") .catch(function(error) { // Handle Errors here. var errorCode = error.code; var errorMessage = error.message; if (errorCode === 'auth/wrong-password') { alert('Wrong password.'); } else { alert(errorMessage); } console.log(error); }); 

My question is: how to get the success event in this method signInWithEmailAndPassword ?

Any help would be greatly appreciated.

+5
source share
2 answers

Just check the code below:

 firebase.auth().signInWithEmailAndPassword(" abc@gmail.com ", "******") .then(function(firebaseUser) { // Success }) .catch(function(error) { // Error Handling }); 
+19
source

This should be done using the onAuthState object. Below is the code to check if the user has logged in successfully or not.

 firebase.auth().onAuthStateChanged(function(user) { if (user) { // User is signed in. } else { // No user is signed in. } }); 

you can run this code after a successful login, BTW there is no return of the SignInWithEmailAndPassword object for verification.

+2
source

Source: https://habr.com/ru/post/1259831/


All Articles