1.1.0 • Published 4 years ago

handle-firebase-error v1.1.0

Weekly downloads
132
License
MIT
Repository
github
Last release
4 years ago

handle-firebase-error

Library for mapping firebase authentication errors to the originating field and a custom error message.

See constants.js for the mapping and error messages which ship with the lib.

Useage

yarn add handle-firebase-error
import {
  createErrorMessageMapper,
  mapErrorToField,
  ErrorCodes
} from "handle-firebase-error";

const errorDictionary = {
  [ErrorCodes.alreadyInUse]: "Your custom error message"
};

const mapErrorToMessage = createErrorMessageMapper(errorDictionary);

try {
  await firebase.auth().signInWithEmailAndPassword(email, password);
  // Errors with error.code `auth/email-already-in-use`
} catch (error) {
  mapErrorToField(errorMessageMapper(error));
  // { email: "Your custom error message" }
}