Catching Errors/Error Handling - createUserWithEmailAndPassword method
See original GitHub issueThanks @tstirrat for sharing the auth.createUserWithEmailAndPassword method on this issue (https://github.com/firebase/emberfire/issues/390). It works great, and by default, errors show up in the console. But the problem is, my custom error callbacks aren’t always firing. It only fires if both the email and password field are set.
Example of the default console log: Error: createUserWithEmailAndPassword failed: First argument “email” must be a valid string. I would like to do a callback on this, so that I can have an error message that says “Email Field Isn’t Set”.
I’ve tried two different approaches, but neither seems to work.
auth.createUserWithEmailAndPassword(email, pass).then(function(userResponse) {
// Create Record in Store
}).catch(function(error) {
console.log('test');
});
and
auth.createUserWithEmailAndPassword(email, pass).then(function(userResponse) {
// Create Record in Store
}, function(error){
console.log('test');
});
Is this a bug? If so, does it have anything to do with the recent angularFire update? https://github.com/firebase/angularfire/releases/tag/v2.0.1
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
See the docs here for createUserWithEmailAndPassword.
The method should return a promise. You should be seeing the code enter the
.catch()
block when there is an error. If not, make sure you are up to date with thefirebase
SDK in yourpackage.json
.The error is suggesting that you are passing something other than a string to the action. Very likely you are passing the value
undefined
. Useconsole.log
or a debug breakpoint to verify the value foremail
inside thecreateUser
action.How are you calling the action
createUser
from your template? You need to pass two parameters to the action in the template, perhaps these are undefined.I fixed the problem by giving both the email and password default empty values of ‘’, which inherently sets them as strings. Now the catch() fires.