diff --git a/src/Options/index.js b/src/Options/index.js index d8f56defca..7973f65029 100644 --- a/src/Options/index.js +++ b/src/Options/index.js @@ -688,7 +688,7 @@ export interface PasswordPolicyOptions { /* Set a callback function to validate a password to be accepted.

If used in combination with `validatorPattern`, the password must pass both to be accepted. */ - validatorCallback: ?() => void; + validatorCallback: ?(password: string) => boolean; /* Set the error message to be sent.

Default is `Password does not meet the Password Policy requirements.` */ diff --git a/types/Options/index.d.ts b/types/Options/index.d.ts index 6a8b1494ac..8c353eb191 100644 --- a/types/Options/index.d.ts +++ b/types/Options/index.d.ts @@ -226,7 +226,7 @@ export interface AccountLockoutOptions { } export interface PasswordPolicyOptions { validatorPattern?: string; - validatorCallback?: () => void; + validatorCallback?: (password: string) => boolean; validationError?: string; doNotAllowUsername?: boolean; maxPasswordAge?: number; diff --git a/types/tests.ts b/types/tests.ts index 15593963f8..320be31d40 100644 --- a/types/tests.ts +++ b/types/tests.ts @@ -36,6 +36,21 @@ async function server() { // $ExpectType ParseServer await parseServer2.start(); + + // passwordPolicy.validatorCallback accepts (password: string) => boolean + // $ExpectType ParseServer + await ParseServer.startApp({ + passwordPolicy: { + validatorCallback: (password: string): boolean => password !== 'badpw', + }, + }); + + await ParseServer.startApp({ + passwordPolicy: { + // $ExpectError + validatorCallback: (password: string): string => password, + }, + }); } function exports() {