From a612b1401e196a4e8a1ebff97089d2ef4cb72743 Mon Sep 17 00:00:00 2001 From: Manuel Trezza <5673677+mtrezza@users.noreply.github.com> Date: Mon, 6 Jan 2025 17:07:32 +0100 Subject: [PATCH] add trigger --- src/Routers/UsersRouter.js | 26 +++++++++++++++++++++++++- src/triggers.js | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Routers/UsersRouter.js b/src/Routers/UsersRouter.js index 70085f988c..aa40449edc 100644 --- a/src/Routers/UsersRouter.js +++ b/src/Routers/UsersRouter.js @@ -438,6 +438,30 @@ export class UsersRouter extends ClassesRouter { async handleResetRequest(req) { this._throwOnBadEmailConfig(req); + const noUserErrorText = 'A user with that email does not exist.'; + + // Get user + const results = await req.config.database.find('_User', { email }, {}, Auth.maintenance(req.config)); + const user = results[0]; + if (!(user instanceof Parse.User)) { + if (req.config.passwordPolicy?.resetPasswordSuccessOnInvalidEmail ?? true) { + return { + response: {}, + }; + } + throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, noUserErrorText); + } + + // Run trigger + await maybeRunTrigger( + TriggerTypes.beforePasswordReset, + req.auth, + user, + null, + req.config, + req.info.context + ); + const { email } = req.body; if (!email) { throw new Parse.Error(Parse.Error.EMAIL_MISSING, 'you must provide an email'); @@ -461,7 +485,7 @@ export class UsersRouter extends ClassesRouter { response: {}, }; } - err.message = `A user with that email does not exist.`; + err.message = noUserErrorText; } throw err; } diff --git a/src/triggers.js b/src/triggers.js index 0f1b632078..7ec9a6bc4b 100644 --- a/src/triggers.js +++ b/src/triggers.js @@ -15,6 +15,7 @@ export const Types = { beforeConnect: 'beforeConnect', beforeSubscribe: 'beforeSubscribe', afterEvent: 'afterEvent', + beforePasswordReset: 'beforePasswordResetRequest', }; const ConnectClassName = '@Connect';