fix(form): display store password complexity requirements in registration form tooltip#2814
Conversation
…tion form tooltip
🦋 Changeset detectedLatest commit: 3ed08b0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| >; | ||
|
|
||
| function getFieldSchema(field: Field) { | ||
| // eslint-disable-next-line complexity |
There was a problem hiding this comment.
I can refactor to abstract the new logic into a smaller function if we don't want this here
|
testing the functionality locally and it worked correctly for me! |
|
|
||
| function getFieldSchema(field: Field) { | ||
| // eslint-disable-next-line complexity | ||
| function getFieldSchema(field: Field, passwordComplexity?: PasswordComplexitySettings | null) { |
There was a problem hiding this comment.
What do you think about falling back to the old password complexity limits if this is null or in some weird case undefined?
There was a problem hiding this comment.
Sorry I missed this yesterday! I think it's taken care of. Basically, I have a fallback for each of the different requirements, and they should match the original hardcoded (minLength of 8, requireNumbers true, etc.). Copy/pasted below for convenience:
/**
* Original fieldSchema for reference:
*
* fieldSchema = z
* .string()
* .min(8, { message: 'Be at least 8 characters long' })
* .regex(/[a-zA-Z]/, { message: 'Contain at least one letter.' })
* .regex(/[0-9]/, { message: 'Contain at least one number.' })
* .regex(/[^a-zA-Z0-9]/, {
* message: 'Contain at least one special character.',
* }
*/
// New
const minLength = passwordComplexity?.minimumPasswordLength ?? 8;
const minNumbers = passwordComplexity?.minimumNumbers ?? 0;
const minSpecialChars = passwordComplexity?.minimumSpecialCharacters ?? 0;
const requireLowerCase = passwordComplexity?.requireLowerCase ?? false;
const requireUpperCase = passwordComplexity?.requireUpperCase ?? false;
const requireNumbers = passwordComplexity?.requireNumbers ?? true;
const requireSpecialChars = passwordComplexity?.requireSpecialCharacters ?? true;…tion form tooltip (#2814)
What/Why?
This PR fixes an issue where the password validation tooltip during customer registration showed hardcoded password complexity requirements instead of the actual requirements configured in the store's BigCommerce Control Panel (Settings > Security & Privacy).
Solution:
Testing
Using the following store settings:

With password set to "a":

With password set to "a1":

With all complexity requirements met:

Migration
Breaking Changes: None - all changes are backward compatible.
What Changed: The
schema()function incore/vibes/soul/form/dynamic-form/schema.tsnow accepts an optional second parameterpasswordComplexityto enable dynamic password validation. TheDynamicForm,DynamicFormSectioncomponents and their associated server actions also accept an optionalpasswordComplexityprop that flows through to the schema.Action Required: If you have custom registration or password forms and want to use store-specific password complexity settings, fetch
passwordComplexitySettingsfrom the GraphQL API (undersite.settings.customers.passwordComplexitySettings) and pass it to yourDynamicFormSectioncomponent and maintain it in your server action's state. If you don't pass it, password validation defaults to: minimum 8 characters, at least one number, and at least one special character.Conflict Resolution: If merging into custom forms, ensure the
passwordComplexityprop is threaded through: Page →DynamicFormSection→DynamicForm→useActionState→schema(). In server actions, addpasswordComplexity?: Parameters<typeof schema>[1]to your state type and include it in all return statements to maintain state consistency.