1 year ago

#373050

test-img

Volvoks

Typescript - What is missing in this build to have a function?

I can't understand what I'm missing, when I send a login request via Postman, it says it's not a function. I am working on authentication part and using typescript.

**// loginMember from Service**
      loginMember = (email: any, password: any) => {
        return new Promise(async (resolve, reject) => {
          try {
            let data = await this.BaseModel.findById({
              email: email,
              password: createPasswordToHash(password),
            });
            return resolve(data);
          } catch (error) {
            return reject(error);
          }
        });
      };

// login Controller

  login = (req: Request, res: Response, next: NextFunction) => {
    loginMember(req.body)
      .then((response: any) => {
        if (response) {
          const member = {
            ...response.toObject(),
            accessToken: generateAccessToken(response.toObject()),
          };
          delete member.password;
          delete member.createdAt;
          delete member.updatedAt;
          return res.status(httpStatus.OK).send(member);
        }
        return res.status(httpStatus.UNAUTHORIZED).send({ error: 'Invalid email or password' });
      })
      .catch((err: { message: string }) => {
        return next(
          new ApiError(
            err.message,
            httpStatus.UNAUTHORIZED,
            'login',
            req.headers['user-agent']?.toString() || 'Unknown'
          )
        );
      });
  };

typescript

authentication

request

postman

http-post

0 Answers

Your Answer

Accepted video resources