Unveiling the method to retrieve AuthErrorCode from Firebase JS SDK without the need for the auth/ prefix

I'm curious about how to retrieve the correct error code in Firebase v10.

public resetPassword(email: string, actionCodeSettings: ActionCodeSettings): Promise<void> {
  return sendPasswordResetEmail(this.auth, email, actionCodeSettings);
}

public async resetPassword(): Promise<void> {
    try {
      await this.resetPassword(this.email, this.actionCodeSettings);
    } catch (error) {
      if (error instanceof FirebaseError && error.message === AuthErrorCodes.INVALID_EMAIL) {
        // This part never executes because AuthErrorCodes.INVALID_EMAIL = "auth/invalid-email" and error.message = "INVALID_EMAIL"
      }
    }
  }
}

When I input an email that is not registered in Firebase, this code returns the following response:

{
  "error": {
    "code": 400,
    "message": "INVALID_EMAIL",
    "errors": [
      {
        "message": "INVALID_EMAIL",
        "domain": "global",
        "reason": "invalid"
      }
    ]
  }
}

The Firebase AuthErrorCodes (link) use codes with an auth/ prefix. I want to access these codes from AuthErrorCode (link), but they are internal. Is there a safe way to handle this error?

Answer №1

The error code (for example, auth/invalid-email) is actually found within the thrown error, not in the response. Therefore, the following code snippet will function as intended:

if (error instanceof FirebaseError && error.code === AuthErrorCodes.INVALID_EMAIL) {
  console.log("caught");
}

An alternative solution could have been to compare against the string value (such as INVALID_EMAIL), but that approach was purposely avoided.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I am looking for a custom script for a splash page that will automatically redirect users to one of three designated pages based on the information stored

As a programmer, I'm well-versed in coding but lack knowledge about creating and utilizing cookies. If anyone could provide guidance on this matter, it would be highly appreciated. I believe I require two concise scripts for this task. 1st Script: T ...

Failure to trigger success or error callbacks in Angular's $http.get request

Trying to access the nutritionix v1_1 API through a get request has been a bit tricky. Despite the function being called successfully and passing the correct data, the $http.get request seems to be causing some trouble. It simply skips over the remaining c ...

Angular 2 - Karma is having trouble locating the external template or style file

The file structure for this project (taken from the Angular 2 official site) is as follows: https://i.stack.imgur.com/A6u58.png Upon starting Karma, I encountered errors indicating that two files were not found under /@angular/... To resolve this issue, ...

Can minification of JS be achieved in a Jekyll environment?

Currently, I am in the process of developing a project with Jekyll and one of the requirements is to minify HTML, CSS, and JS. I was wondering if Jekyll has built-in features for JS minification. It may seem like a simple question, but since I am new to ...

What exactly is the significance of Android TextInputLayout's transitionName and transitionGroup?

Recently, I came across the firebaseUI auth project and stumbled upon a few instances of TextInputLayouts that contain references to transitionName and transitionGroup. Despite searching online for more information on how to utilize them and their actual ...

Mastering Interpolation in React with TypeScript is essential for creating dynamic and interactive UI components. By leveraging the

Incorporating and distributing CSS objects through ChakraUI presents a simple need. Given that everything is inline, it seems the main issue revolves around "& > div". However, one of the TypeScript (TS) errors highlights an unexpected flagging of ...

Setting up Firestore with @angular/fire 17 and Ionic @ionic/angular 7.6.2 for full offline functionality: a step-by-step guide

Recently, I've delved into app development using Angular, Ionic, and Firebase. Currently, I'm grappling with the challenge of setting up offline capabilities/unlimited cache size with AngularFire, and it's been days of confusion and dead-en ...

Can TypeScript allow for type checking within type definitions?

I've developed a solution for returning reactive forms as forms with available controls listed in IntelliSense. It works well for FormControls, but I'm now looking to extend this functionality to include FormGroups that are part of the queried pa ...

Retrieving document attributes from a Mongoose Model with the help of Typescript

Incorporating Typescript with Mongoose, my aim is to retrieve properties from a Model. Taking the illustrated UserModel as an example import mongoose, { Schema } from 'mongoose'; const userSchema: Schema = new mongoose.Schema({ _id: mongoos ...

Iterating through a nested array of objects to merge and accumulate values

Just started learning Javascript. I've been trying to wrap my head around it for hours, looking at examples, but still struggling. I'm working with an array of objects that have nested properties which I need to loop through and consolidate. ...

The useNavigate() hook from react-router-dom is not properly setting the id in the URL path

I am currently using react-router-dom v6 for my routing needs. My goal is to pass an ID in the navigate URL path. Here is the onClick method and button code that I am working with: let navigate = useNavigate(); const routeChange = (id) => { let ...

Determine the specific button that was clicked within a React component

I have a challenge with dynamically generated material UI buttons. I am trying to identify which button was clicked by obtaining the value of the name attribute that I assigned to each button. Is there a way to accomplish this? In essence, I need to retrie ...

Using Types as Variables in TypeScript

Currently in the process of writing a TypeScript class factory, my goal is to have a function output a type as its result. While TypeScript handles types as inputs using generics effectively, I am facing challenges when it comes to dealing with types as ou ...

Enhancing data management with Vuex and Firebase database integration

Within my app, I am utilizing Firebase alongside Vuex. One particular action in Vuex looks like this: async deleteTodo({ commit }, id) { await fbs.database().ref(`/todolist/${store.state.auth.userId}/${id}`) .remove() .then ...

What is the correct way to upload an image using the Express static middleware?

Just diving into express, I have this setup in my server: app.use(express.static(path.join(__dirname, 'includes'))); When it comes to my client-side JavaScript, I'm simply using the URL like so: var img = $("<img />").attr('s ...

Leveraging vue.js props in the mounted function

In my current Vue.js project, I have encountered an issue while using props to pass a value from one component to another. The value received from the props is stored in a variable called "this.Id". I am able to display this value using an alert within the ...

Create directories in a nested structure using a multi-level JSON object with async.js

DEFINITION NewMethod#generateDirectoriesFromJSON (data, cb); data: JSON object. cb: Callback function. Parameters: err (Error), directoriesCreated (Boolean, true if at least one directory has been created). Assuming that the NewMethod class includes a ...

Tips for effectively implementing React.usecallback

Looking for a way to rewrite the handleClick method using React.useCallback in a function called Parent, which is triggered by a button click event in React and TypeScript. function Parent () { const [isOpen, setIsOpen] = React.useState(false); ...

Switching individual items created by a v-for loop in Nuxt.js

I am struggling to create a simple accordion-like structure with the ability to toggle individual elements: <div v-for="qa, j in group.questions_answers" :key="j"> <div class="question" @click="toggle()" & ...

"Empty array conundrum in Node.js: A query on asynchronous data

I need assistance with making multiple API calls and adding the results to an array before returning it. The issue I am facing is that the result array is empty, likely due to the async nature of the function. Any help or suggestions would be greatly appre ...