Skip to content

Commit 3781785

Browse files
authored
feat: add documentation for password reset (#963)
1 parent 7811d49 commit 3781785

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

_includes/cloudcode/cloud-code.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,52 @@ Parse.Cloud.afterLogout(async request => {
761761
- if a user logs out and no `_Session` object was found to delete
762762
- if a `_Session` object is deleted without the user logging out by calling the logout method of an SDK
763763
764+
## beforePasswordResetRequest
765+
766+
*Available only in Cloud Code on Parse Server >= 8.5.0.*
767+
768+
The `beforePasswordResetRequest` trigger is invoked before a password reset email is sent. It is triggered after the user is found by email, but before the reset token is generated and the email is sent. It can be used for blocking password reset requests, implementing rate limiting, or adding additional validation logic.
769+
770+
An example would be to prevent sending a password reset email if the user has a ban flag set in your application.
771+
772+
```javascript
773+
Parse.Cloud.beforePasswordResetRequest(request => {
774+
if (request.object.get('banned')) {
775+
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, 'User is banned.');
776+
}
777+
});
778+
```
779+
780+
You can also add rate limiting to prevent abuse of the password reset endpoint:
781+
782+
```javascript
783+
Parse.Cloud.beforePasswordResetRequest(async request => {
784+
if (request.object.get('banned')) {
785+
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, 'User is banned.');
786+
}
787+
}, {
788+
rateLimit: {
789+
requestLimit: 5,
790+
windowMs: 60_000
791+
}
792+
});
793+
```
794+
795+
Considerations:
796+
797+
- The user object is available on `request.object`, which is the user who requested the password reset.
798+
- If the function throws an error, the password reset email will not be sent.
799+
800+
The trigger will run:
801+
802+
- When a password reset is requested via `/requestPasswordReset` endpoint.
803+
- After the user is found by email address.
804+
- Before the reset token is generated and the email is sent.
805+
806+
The trigger won't run:
807+
808+
- If the email address doesn't match any user in the system.
809+
764810
# LiveQuery Triggers
765811
766812
## beforeConnect

_includes/rest/users.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ print(result)
186186

187187
If successful, the response body is an empty JSON object.
188188

189+
You can use the [`beforePasswordResetRequest`]({{ site.baseUrl }}/cloudcode/guide/#beforepasswordresetrequest) Cloud Code trigger to add custom validation logic before the password reset email is sent.
190+
189191
## Retrieving Users
190192

191193
You can also retrieve the contents of a user object by sending a GET request to the URL returned in the location header when it was created. For example, to retrieve the user created above:

0 commit comments

Comments
 (0)