MongoDB (mongodb package version 4.0.x and 4.1.0): Showing error on 1st time wrong password attempt
Here is my error

```node
C:\Web Dev\Codversity\node_modules\rate-limiter-flexible\lib\RateLimiterMongo.js:118
    res.isFirstInDuration = doc.points === changedPoints;
                                ^

TypeError: Cannot read property 'points' of null
    at RateLimiterMongo._getRateLimiterRes (C:\Web Dev\Codversity\node_modules\rate-limiter-flexible\lib\RateLimiterMongo.js:118:33)
    at RateLimiterMongo._afterConsume (C:\Web Dev\Codversity\node_modules\rate-limiter-flexible\lib\RateLimiterStoreAbstract.js:51:22)
    at C:\Web Dev\Codversity\node_modules\rate-limiter-flexible\lib\RateLimiterStoreAbstract.js:205:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
```

and here's my code for login middleware

```ts
import mongoose from "mongoose";
import passport from "passport";
import { RateLimiterMongo } from "rate-limiter-flexible";

const maxWrongAttemptsByIPperDay = 100;
const maxConsecutiveFailsByEmailAndIP = 3;

// the rate limiter instance counts and limits the number of failed logins by key
const limiterSlowBruteByIP = new RateLimiterMongo({
  storeClient: mongoose.connection,
  keyPrefix: "codversity_login_fail_ip_per_day",
  // maximum number of failed logins allowed. 1 fail = 1 point
  // each failed login consumes a point
  points: maxWrongAttemptsByIPperDay,
  // delete key after 24 hours
  duration: 60 * 60 * 24,
  // number of seconds to block route if consumed points > points
  blockDuration: 60 * 60 * 24, // Block for 1 day, if 100 wrong attempts per day
});

const limiterConsecutiveFailsByEmailAndIP = new RateLimiterMongo({
  storeClient: mongoose.connection,
  keyPrefix: "codversity_login_fail_consecutive_email_and_ip",
  points: maxConsecutiveFailsByEmailAndIP,
  duration: 60, // Delete key after 1 hour
  blockDuration: 60, // Block for 1 hour
});

// create key string
const getEmailIPkey = (email, ip) => `${email}_${ip}`;

// rate-limiting middleware controller
export async function loginRouteRateLimit(req, res, next) {
  const ipAddr = req.ip;
  const emailIPkey = getEmailIPkey(req.body.email, ipAddr);

  // get keys for attempted login
  const [resEmailAndIP, resSlowByIP] = await Promise.all([
    limiterConsecutiveFailsByEmailAndIP.get(emailIPkey),
    limiterSlowBruteByIP.get(ipAddr),
  ]);

  let retrySecs = 0;
  // Check if IP or email + IP is already blocked
  if (
    resSlowByIP !== null &&
    resSlowByIP.consumedPoints > maxWrongAttemptsByIPperDay
  ) {
    retrySecs = Math.round(resSlowByIP.msBeforeNext / 1000) || 1;
  } else if (
    resEmailAndIP !== null &&
    resEmailAndIP.consumedPoints > maxConsecutiveFailsByEmailAndIP
  ) {
    retrySecs = Math.round(resEmailAndIP.msBeforeNext / 1000) || 1;
  }

  // the IP and email + ip are not rate limited
  if (retrySecs > 0) {
    // sets the response’s HTTP header field
    res.set("Retry-After", String(retrySecs));
    req.flash(
      "error",
      `Too many login attempts. Retry after ${retrySecs} seconds`
    );
    res.status(429).redirect("/login");
  } else {
    passport.authenticate("local", async function (err, user, info) {
      if (err) {
        return next(err);
      }
      if (!user) {
        // Consume 1 point from limiters on wrong attempt and block if limits reached
        try {
          const promises = [limiterSlowBruteByIP.consume(ipAddr)];
          // check if user exists by checking if authentication failed because of an incorrect password
          if (info.name === "IncorrectPasswordError") {
            // Count failed attempts by Email + IP only for registered users
            promises.push(
              limiterConsecutiveFailsByEmailAndIP.consume(emailIPkey)
            );
          }
          await Promise.all(promises);
          req.flash("error", info.message);
          res.redirect("/login");
        } catch (rlRejected) {
          if (rlRejected instanceof Error) {
            throw rlRejected;
          } else {
            const timeOut =
              String(Math.round(rlRejected.msBeforeNext / 1000)) || 1;
            res.set("Retry-After", timeOut);
            req.flash(
              "error",
              `Too many login attempts. Retry after ${timeOut} seconds`
            );
            res.status(429).redirect("/login");
          }
        }
      }
      // If passport authentication successful
      if (user) {
        console.log("successful login");
        if (resEmailAndIP !== null && resEmailAndIP.consumedPoints > 0) {
          // Reset limiter based on IP + email on successful authorization
          await limiterConsecutiveFailsByEmailAndIP.delete(emailIPkey);
        }
        // login (Passport.js method)
        req.logIn(user, function (err) {
          if (err) {
            return next(err);
          }
          return res.redirect(req.session.returnTo || "/");
        });
      }
    })(req, res, next);
  }
}
```