From afbc8a46383da1e429614f34d79b9167bcb7d8d8 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 13 Jan 2021 21:06:13 -0500 Subject: [PATCH] chore: improves typing within incLoginAttempts method --- src/collections/init.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/collections/init.ts b/src/collections/init.ts index 02681d50d6..b0b6768e4b 100644 --- a/src/collections/init.ts +++ b/src/collections/init.ts @@ -27,8 +27,14 @@ export default function registerCollections(ctx: Payload): void { const { maxLoginAttempts, lockTime } = collection.auth; if (maxLoginAttempts > 0) { + type LoginSchema = { + loginAttempts: number + lockUntil: number + isLocked: boolean + }; + // eslint-disable-next-line func-names - schema.methods.incLoginAttempts = function (this: any, cb) { + schema.methods.incLoginAttempts = function (this: mongoose.Document & LoginSchema, cb) { // Expired lock, restart count at 1 if (this.lockUntil && this.lockUntil < Date.now()) { return this.updateOne({ @@ -37,7 +43,6 @@ export default function registerCollections(ctx: Payload): void { }, cb); } - type LoginSchema = { loginAttempts: number; }; const updates: UpdateQuery = { $inc: { loginAttempts: 1 } }; // Lock the account if at max attempts and not already locked if (this.loginAttempts + 1 >= maxLoginAttempts && !this.isLocked) {