1.0.8 • Published 5 months ago

firebase-error-handler v1.0.8

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

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 CodeMessage
auth/email-already-in-useThis email is already in use. Try logging in instead.
auth/invalid-emailInvalid email format. Please enter a valid email address.
auth/user-disabledThis user account has been disabled.
auth/wrong-passwordIncorrect password. Please try again.
auth/user-not-foundNo user found with this email.
auth/weak-passwordPassword should be at least 6 characters.
auth/invalid-credentialInvalid login credentials.
auth/network-request-failedNetwork error. Please check your connection.
auth/account-exists-with-different-credentialAn account already exists with this email. Try signing in with a different method.
auth/credential-already-in-useThis credential is already linked to another account.
auth/operation-not-allowedThis authentication method is not enabled. Contact support.
auth/popup-blockedPopup was blocked. Please enable popups in your browser.
auth/popup-closed-by-userYou closed the popup before signing in. Try again.
auth/unauthorized-domainThis domain is not authorized for authentication. Contact support.
auth/invalid-action-codeThe password reset or verification link is invalid or expired.
auth/expired-action-codeThis link has expired. Please request a new one.
auth/id-token-expiredYour session has expired. Please log in again.
auth/id-token-revokedYour session was revoked. Log in again.
auth/session-cookie-expiredSession has expired. Please refresh or log in again.
auth/session-cookie-revokedSession has been revoked. Please log in again.
auth/captcha-check-failedCaptcha verification failed. Try again.
auth/invalid-phone-numberInvalid phone number format. Check and try again.
auth/quota-exceededToo many requests. Please try again later.
auth/multi-factor-auth-requiredMulti-factor authentication is required. Check your email or device.
auth/mfa-info-not-foundNo multi-factor authentication info found for this user.
auth/too-many-requestsToo many attempts. Please wait and try again later.
auth/internal-errorAn 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.

1.0.8

5 months ago

1.0.7

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.0

5 months ago