Customizing Authentication Error Message for Firebase in ReactJS
While Firebase documentation is generally good, there are some areas, particularly in the Authentication section, where the error messages could use improvement or clearer explanations.
To customize error messages when creating a new user with email and password in Firebase, you can create a file named getFirebaseErrorMessage.js to store text values corresponding to error messages. This file will serve as a utility function for handling and customizing error messages.
export const getFirebaseErrorMessage = code => { var message = null; switch (code) { case "auth/user-not-found": message = "User doesn't exist." break; case "auth/email-already-exists": message = 'Email already exist'; break; case "auth/invalid-credential": message = 'Invalid Credential'; break; case "auth/invalid-email": message = 'Invalid Email'; break; case "auth/invalid-password": message = 'Incorrect Password'; break; case "auth/too-many-requests": message = "You're exceed the limit. Try again after sometime."; break; default: message = 'Something went wrong'; break; } return message; }