1.0.8 • Published 5 months ago
firebase-error-handler v1.0.8
Firebase Error Handler
A simple package to convert Firebase error codes into human-readable messages. This helps in improving user experience by displaying friendly error messages instead of cryptic Firebase error codes.
Installation
You can install this package via npm or yarn:
npm install firebase-error-handler
or
yarn add firebase-error-handler
Usage
CommonJS (require
)
const parseFirebaseError = require("firebase-error-handler");
// Using error object
console.log(parseFirebaseError({ code: "auth/wrong-password" }));
// Output: "Incorrect password. Please try again."
// Using error code directly
console.log(parseFirebaseError("auth/email-already-in-use"));
// Output: "This email is already in use. Try logging in instead."
ES Module (import
)
import parseFirebaseError from "firebase-error-handler";
// Using error object
console.log(parseFirebaseError({ code: "auth/wrong-password" }));
// Output: "Incorrect password. Please try again."
// Using error code directly
console.log(parseFirebaseError("auth/email-already-in-use"));
// Output: "This email is already in use. Try logging in instead."
CommonJS (Named Import via require
)
const { getFirebaseErrorMessage } = require("firebase-error-handler");
console.log(getFirebaseErrorMessage({ code: "auth/email-already-in-use" }));
// Output: "This email is already in use. Try logging in instead."
ES Module (Named Import via import
)
import { getFirebaseErrorMessage } from "firebase-error-handler";
console.log(getFirebaseErrorMessage({ code: "auth/email-already-in-use" }));
// Output: "This email is already in use. Try logging in instead."
Example in Firebase Authentication
const signIn = async (email, password) => {
try {
await auth.signInWithEmailAndPassword(email, password);
} catch (error) {
console.log(getFirebaseErrorMessage(error));
}
};
Run Without Installing (Using npx) CLI
You can run it directly without installing:
npx firebase-error-handler auth/wrong-password
Supported Error Codes
The package currently supports the following Firebase authentication error codes:
Error Code | Message |
---|---|
auth/email-already-in-use | This email is already in use. Try logging in instead. |
auth/invalid-email | Invalid email format. Please enter a valid email address. |
auth/user-disabled | This user account has been disabled. |
auth/wrong-password | Incorrect password. Please try again. |
auth/user-not-found | No user found with this email. |
auth/weak-password | Password should be at least 6 characters. |
auth/invalid-credential | Invalid login credentials. |
auth/network-request-failed | Network error. Please check your connection. |
auth/account-exists-with-different-credential | An account already exists with this email. Try signing in with a different method. |
auth/credential-already-in-use | This credential is already linked to another account. |
auth/operation-not-allowed | This authentication method is not enabled. Contact support. |
auth/popup-blocked | Popup was blocked. Please enable popups in your browser. |
auth/popup-closed-by-user | You closed the popup before signing in. Try again. |
auth/unauthorized-domain | This domain is not authorized for authentication. Contact support. |
auth/invalid-action-code | The password reset or verification link is invalid or expired. |
auth/expired-action-code | This link has expired. Please request a new one. |
auth/id-token-expired | Your session has expired. Please log in again. |
auth/id-token-revoked | Your session was revoked. Log in again. |
auth/session-cookie-expired | Session has expired. Please refresh or log in again. |
auth/session-cookie-revoked | Session has been revoked. Please log in again. |
auth/captcha-check-failed | Captcha verification failed. Try again. |
auth/invalid-phone-number | Invalid phone number format. Check and try again. |
auth/quota-exceeded | Too many requests. Please try again later. |
auth/multi-factor-auth-required | Multi-factor authentication is required. Check your email or device. |
auth/mfa-info-not-found | No multi-factor authentication info found for this user. |
auth/too-many-requests | Too many attempts. Please wait and try again later. |
auth/internal-error | An internal error occurred. Try again later. |
More error codes will be added in future updates.
Contributing
Feel free to contribute by adding more error codes or improving the package! Fork the repo and submit a pull request.
License
This project is licensed under the MIT License.