0.1.4 • Published 7 months ago

friendly-firebase-errors v0.1.4

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

Friendly Firebase Errors

A utility for converting Firebase Auth errors into user-friendly messages. This package helps developers transform Firebase error codes into human-readable and customizable error messages.

Features

  • Comprehensive Coverage: Includes all Firebase Auth error codes.
  • Customizable Messages: Override default messages for any error code.
  • Debugging Support: Returns the original error object alongside the friendly message.
  • Type Safety: Fully typed for seamless TypeScript integration.

Installation

npm install friendly-firebase-errors

Usage

Basic Usage

Transform a Firebase error into a user-friendly message:

import { friendlyFirebaseError } from 'friendly-firebase-errors';

const error = { code: "auth/code-expired", message: "The code has expired." };
const result = friendlyFirebaseError(error);

console.log(result.friendlyMessage); 
// "The code has expired. Please request a new one."

Custom Messages

You can override default messages with your own custom ones:

const customMessages = {
  "auth/code-expired": "Oops! Your code expired. Try again.",
};

const error = { code: "auth/code-expired", message: "The code has expired." };
const result = friendlyFirebaseError(error, customMessages);

console.log(result.friendlyMessage); 
// "Oops! Your code expired. Try again."

API Reference

friendlyFirebaseError

Parameters

  1. error: The Firebase error object with the following structure:

    • code: A Firebase error code (e.g., auth/code-expired).
    • message (optional): Additional details about the error.
  2. customErrorMap (optional): An object containing custom messages for specific error codes.

Returns

  • An object with:
    • friendlyMessage: A user-friendly error message.
    • originalError: The original Firebase error object.

Default Error Messages

Below is the complete list of error codes and their default friendly messages:

Error CodeDefault Message
auth/admin-restricted-operationThis operation is restricted to administrators.
auth/argument-errorInvalid argument provided. Please check the input and try again.
auth/app-not-authorizedThis app is not authorized to connect to Firebase. Please check the configuration.
auth/app-not-installedThe requested app is not installed on this device.
auth/captcha-check-failedThe CAPTCHA check failed. Please try again.
auth/code-expiredThe code has expired. Please request a new one.
auth/cordova-not-readyThe Cordova framework is not ready. Please try again later.
auth/cors-unsupportedYour browser does not support cross-origin requests. Try a different browser.
auth/credential-already-in-useThis credential is already linked to another account.
auth/custom-token-mismatchThere is a mismatch with the provided custom token.
auth/requires-recent-loginYou need to log in again to perform this action.
auth/dependent-sdk-initialized-before-authAnother SDK was initialized before Auth. Please check your setup.
auth/dynamic-link-not-activatedDynamic links are not activated for this project.
auth/email-change-needs-verificationYou must verify your email address before making changes.
auth/email-already-in-useThis email is already associated with an account. Try logging in or resetting your password.
auth/expired-action-codeThe action code has expired. Please request a new one.
auth/cancelled-popup-requestThe popup request was canceled. Please try again.
auth/internal-errorAn internal error occurred. Please try again later.
auth/weak-passwordYour password is too weak. Please use a stronger password.
auth/web-storage-unsupportedYour browser does not support web storage. Please try a different browser.
auth/already-initializedThe Firebase app has already been initialized.
......

For the complete list of error codes, refer to the DEFAULT_MESSAGES object in the source code.


Contributing

Contributions are welcome! Please open an issue or submit a pull request to enhance the package.


License

This project is licensed under the MIT License.


0.1.4

7 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago