Make passwordPolicy validatorCallback asynchronous

Open Beginner friendly
#10,472 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet

Research direction

Start by reading RestWrite.js and the PasswordPolicyOptions type declaration to trace the validatorCallback invocation and its typing. Verify that synchronous and asynchronous callbacks are both supported and that the declaration accepts Promise; check the related password-policy behavior before considering the work done.

Written by the indexing model from the issue text.

Description

type:feature
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 https://github.com/parse-community/parse-server/issues/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
  1. Send a login/sign up request with a password
  2. Expect an asynchronous operation to happen inside the validation
Alternatives / Workarounds

Custom logic in beforePasswordResetRequest, beforeLogin and beforeSave for _User

3rd Party References
Dominant language
JavaScript
Stars
21.4k
Forks
4.8k
Avg merge
7h 45m
Merged PRs (30d)
11

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from parse-community/parse-server

All issues in parse-community/parse-server

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.