I am programming an Ionic app and have decided to use Firebase to simplify authentication. I have set up the username and password login and it works fine. The way I have it currently set up, if there is an error during login (like misspelled password), then the error will be displayed in the logs. Now, this error isn't very pretty and not what I would like the end user to see. I have been trying to figure out how to create a custom error message for different events so the user will see, "Password is Incorrect" instead of "Error: The specified password is incorrect.". In that example, its not much different, but you get the point.
Here is a sample of the login code:
$scope.login = function(username, password) {
var fbAuth = $firebaseAuth(fb);
fbAuth.$authWithPassword({
email: username,
password: password
}).then(function(authData) {
$location.path('/tab')
}).catch(function(error) {
console.error("ERROR: " + error);
});
}
There is an error code for each error, but I'm not sure how to harness that to create a custom error message based on the error.
Any ideas? Thanks!
I am programming an Ionic app and have decided to use Firebase to simplify authentication. I have set up the username and password login and it works fine. The way I have it currently set up, if there is an error during login (like misspelled password), then the error will be displayed in the logs. Now, this error isn't very pretty and not what I would like the end user to see. I have been trying to figure out how to create a custom error message for different events so the user will see, "Password is Incorrect" instead of "Error: The specified password is incorrect.". In that example, its not much different, but you get the point.
Here is a sample of the login code:
$scope.login = function(username, password) {
var fbAuth = $firebaseAuth(fb);
fbAuth.$authWithPassword({
email: username,
password: password
}).then(function(authData) {
$location.path('/tab')
}).catch(function(error) {
console.error("ERROR: " + error);
});
}
There is an error code for each error, but I'm not sure how to harness that to create a custom error message based on the error.
Any ideas? Thanks!
Share Improve this question asked Jun 23, 2015 at 23:01 cfly24cfly24 1,9623 gold badges27 silver badges61 bronze badges1 Answer
Reset to default 8The error is embedded in error.code.
Then write a seperate function that catched this error and displays a message:
function(error){
switch (error.code)
case "INVALID_USER":
$scope.message = "custom message"
// etc
}
You can find the list of possible error codes in the firebase documentation here: API documentation