From cb5f1dbf9b6d28f292b00791d1cfc54704673d7b Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Sat, 6 Sep 2025 00:59:38 -0400 Subject: [PATCH] Password reset tokens now auto-expire when new reset requests are made. --- src/schemas/user/passwordResetSchema.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/schemas/user/passwordResetSchema.js b/src/schemas/user/passwordResetSchema.js index 2822594..ecba77f 100644 --- a/src/schemas/user/passwordResetSchema.js +++ b/src/schemas/user/passwordResetSchema.js @@ -72,6 +72,12 @@ passwordResetSchema.pre('save', async function (next){ this.ipHash = hashUtil.hashIP(this.ipHash); } + //If the user was modified (usually only on document initialization) + if(this.isModified('user')){ + //Delete previous requests for the given user + const requests = await this.model().deleteMany({user: this.user._id}); + } + next(); });