Resolving issues with ESLint error related to Promise executor functions

Two warnings are triggered by the code block below

  1. ESLint Warning: Avoid using async function as Promise executor. (no-async-promise-executor)
  2. ESLint Warning: Function argument expects void return, but returns a Promise instead.
    (@typescript-eslint/no-misused-promises)

How can we refactor this code to eliminate these warning messages?

async handleLogin(email: string, password: string, redirectTo: string): Promise<unknown> {
  return new Promise(async (resolve, reject) => {
    const { error, data } = await this.supabaseClient.auth.signIn(
      { email: email, password: password },
      { redirectTo: redirectTo }
    );
    if (error) {
      reject(error);
    } else {
      resolve(data);
    }
  });
}

Answer №1

const validateSignIn = async (email: string, password: string, redirectTo: string) => {
    const { error, data } = await this.supabaseClient.auth.signIn(
      { email: email, password: password },
      { redirectTo: redirectTo }
    );
    if (error) {
      throw new Error(error);
    }

    return data
  });
}

Avoid the use of promises entirely, and be sure to handle errors by throwing an exception.

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

No search results found for Mongoose text search query

Despite using Mongoose 5.7.8 for my app, the text search feature is not yielding any results. Below is a schema/model example: import mongoose, { Document, Schema } from 'mongoose'; import { Moment } from 'moment'; import { IUser } fr ...

Obtaining the interface for a Typegoose class model

I am currently exploring how to create an abstraction for Mongo model functions and looking into ways to reuse the model interface from a typegoose class. My goal is to have a function like this: import CountryModel, { Country } from '../../models/ ...

The functionality to generate personalized worldwide timezone pipe is not functioning

I'm completely new to Angular and I've been working on creating a custom pipe for adjusting timezones. The idea is to allow users to select their preferred timezone and have the offset applied accordingly. To start, I created a file called timez ...

Steps for creating a dynamic validation using a new form control

I have an item that needs to generate a form const textBox = { fontColor: 'blue', fontSize: '18', placeholder: 'email', name: 'input email', label: 'john', validation: { required: false } ...

Why is the removal of this type assertion in TypeScript causing an issue?

Why is TypeScript refusing to compile this code snippet? interface TaggedProduct { tag: string; } interface Product { tag?: string; } const tagProduct = (product: Product): TaggedProduct => { const tag: string = "anything"; pro ...

Error: The module could not be found due to an inability to resolve the parsed request

I am working on a project that uses class components as a requirement by the company, and I cannot switch to function components. After running elint --fix and restarting the project, I encountered an error that is specific to just one file. The error me ...

What is the reason for encountering the error message "Property 'floatThead' does not exist on type 'JQuery<any>' when trying to use floatThead in Angular/TypeScript?

For my project, I am incorporating the third-party jQuery library called https://github.com/mkoryak/floatThead. To work with Bootstrap and jQuery, I have installed them using NPM through the command line. Additionally, I have used NPM to install floatThea ...

Different ways to handle dialogs in React with TypeScript

I'm currently working on developing a modal component in React TypeScript and I'm facing some issues in determining the correct type for a reference of an HTML dialog element. import { useRef } from 'react' const MyModal: React.FC = () ...

Implement angular translation as an argument for a notification function

Can anyone help me figure out how to pass a string message as a parameter to my AddRemoveUserOfGroupGeneral function? I am using matToolTip without any issues, but I'm struggling to pass it to my function: <button mat-raised-button color="prim ...

Having trouble retrieving the parent object in Angular OnInit method?

I am facing an issue with attaching a custom validator to an Angular Form Control. The Form Controls are initialized in the ngOnInit method, and I want the validator to check if a field has input only when a boolean class member this.shouldCheck is true. ...

Can you provide guidance on adjusting the dimensions of the Carousel element within the ShadCN UI?

My React component setup currently includes the following: "use client"; import Autoplay from "embla-carousel-autoplay"; import { Card, CardContent } from "@/components/ui/card"; import { Carousel, CarouselContent, ...

Node.js with TypeScript: The block-scoped variable 'events' cannot be redeclared

I am currently in the process of migrating a Node + ES6 project to TypeScript. My goal is to stick to ES6 (since I am using Node 7.x) and incorporate the use of Map. Upon running tsc -p, the following errors are displayed: src/actions.ts(3,9): error TS2 ...

Turn off VSCode's auto-suggestion feature for inserting curly braces

Recently, I've been facing some issues with the autocomplete feature in vscode. After hitting enter, the autocomplete seems to disable itself, requiring me to press Control+Space to make it pop up and select an option like in this image: https://i.s ...

React Testing Library - Screen debug feature yields results that may vary from what is displayed in the

Greetings to all who come across this message. I have developed a tic-tac-toe game in typescript & redux with a 3x3 grid, and now I am facing some challenges while trying to write unit tests for it. Consider the following game board layout where X represen ...

When declaring an array of numbers in sequelize-typescript, it triggers a TypeScript error

In my application, I am working with PostgreSQL, Sequelize, Sequelize-TypeScript, and TypeScript. I have a need for a table called Role where each role has multiple permissions of type integer. I'm following the guidelines provided in the sequelize-ty ...

What are some ways to prevent Visual Studio from adding an extra space in JavaScript code during the build or rebuild process?

In my Visual Studio 2019 Enterprise setup, I have noticed that when I build or rebuild my ASP.net 4 MVC solution, my JavaScript files are regenerated by TypeScript. The issue is that the new JavaScript files always end up with a single trailing space after ...

Creating subclass mappings and defining subclasses dynamically using Typescript at runtime

I am puzzled by the structure of 3 classes: A, B, and C. Both B and C extend the abstract class A. abstract class A { public name: string; constructor(name: string) { this.name = name; } abstract getName(): string; } class B extends A { g ...

The role of providers in Angular applications

After creating a component and service in my project, I followed the documentation's instruction to include the service in the providers metadata of the component for injection. However, I found that it still works fine even without mentioning it in t ...

Unable to install Typescript using npm

I recently started a tutorial on Typescript and wanted to install it globally using npm. npm i typescript -g However, I encountered an issue where the installation gets stuck on the first line and displays the following message: (⠂⠂⠂⠂⠂⠂⠂⠂ ...

Retrieving information from a .json file using TypeScript

I am facing an issue with my Angular application. I have successfully loaded a .json file into the application, but getting stuck on accessing the data within the file. I previously asked about this problem but realized that I need help in specifically und ...