Skip to content

Commit

Permalink
add trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
mtrezza committed Jan 6, 2025
1 parent a579eeb commit a612b14
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/Routers/UsersRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/triggers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const Types = {
beforeConnect: 'beforeConnect',
beforeSubscribe: 'beforeSubscribe',
afterEvent: 'afterEvent',
beforePasswordReset: 'beforePasswordResetRequest',
};

const ConnectClassName = '@Connect';
Expand Down

0 comments on commit a612b14

Please sign in to comment.