New Feature / Enhancement Checklist
Current Limitation
Custom validation on passwords may include asynchronous operations, such as hitting an special endpoint. The current validator only runs synchronously.
Feature / Enhancement Description
RestWrite.js should wrap the validatorCallback invocation with await Promise.resolve(...) so that both synchronous (boolean) and asynchronous (Promise) callbacks are supported. The type declaration for validatorCallback in PasswordPolicyOptions should be updated accordingly to (password: string) => boolean | Promise<boolean>.
Also worth mentioning the typing issue in #10471
// Before
if (
this.config.passwordPolicy.validatorCallback &&
!this.config.passwordPolicy.validatorCallback(this.data.password)
) { ... }
// After
if (this.config.passwordPolicy.validatorCallback) {
const isValid = await Promise.resolve(
this.config.passwordPolicy.validatorCallback(this.data.password)
);
if (!isValid) {
return Promise.reject(new Parse.Error(Parse.Error.VALIDATION_ERROR, policyError));
}
}
Example Use Case
- Send a login/sign up request with a password
- Expect an asynchronous operation to happen inside the validation
Alternatives / Workarounds
Custom logic in beforePasswordResetRequest, beforeLogin and beforeSave for _User
3rd Party References
New Feature / Enhancement Checklist
Current Limitation
Custom validation on passwords may include asynchronous operations, such as hitting an special endpoint. The current validator only runs synchronously.
Feature / Enhancement Description
RestWrite.jsshould wrap thevalidatorCallbackinvocation withawait Promise.resolve(...)so that both synchronous (boolean) and asynchronous (Promise) callbacks are supported. The type declaration forvalidatorCallbackinPasswordPolicyOptionsshould be updated accordingly to(password: string) => boolean | Promise<boolean>.Also worth mentioning the typing issue in #10471
Example Use Case
Alternatives / Workarounds
Custom logic in
beforePasswordResetRequest,beforeLoginandbeforeSave for _User3rd Party References