WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Using custom password validation hook in users collection doesen't prevent the collapsible from closong #14858

@urbanczykb

Description

@urbanczykb

Describe the Bug

The only way to control a user password strength is to use a custom beforeValidate hook.
The UI in the user's collection has a collapsible that opens when the 'change password' button is pressed:

Image Image

Once there is a validation error the collapsible closes:

Image

Reproduction steps:

Link to the code that reproduces this issue

https://github.com/payloadcms/payload/tree/main/templates/website

Reproduction Steps

  1. In users collection config add an example hook:
  hooks: {
    beforeValidate: [
      (data) => {
        const { password } = data.data || {}
        if (password.length < 8) {
          throw new ValidationError({
            collection: 'users',
            errors: [
              {
                message:
                  'Password has to be at least 8 characters long',
                path: 'password',
              },
            ],
          })
        }
      },
    ],
  },
  1. Enter a password that is at least 3 characters long but shorter than 8 (ex. 5 characters)
  2. Hit save
  3. The collapsible get's closed, only a toast with error is visible
  4. Click the 'change password' button to see the validation error
  5. A validation error is visible

Expected result: Once validation fails the collapsible should stay open

Which area(s) are affected?

area: ui

Environment Info

Binaries:
  Node: 20.19.0
  npm: 10.8.2
  Yarn: N/A
  pnpm: 10.3.0
Relevant Packages:
  payload: 3.67.0
  next: 15.4.4
  @payloadcms/db-sqlite: 3.67.0
  @payloadcms/drizzle: 3.67.0
  @payloadcms/email-nodemailer: 3.67.0
  @payloadcms/graphql: 3.67.0
  @payloadcms/live-preview: 3.67.0
  @payloadcms/live-preview-react: 3.67.0
  @payloadcms/next/utilities: 3.67.0
  @payloadcms/payload-cloud: 3.67.0
  @payloadcms/plugin-seo: 3.67.0
  @payloadcms/richtext-lexical: 3.67.0
  @payloadcms/translations: 3.67.0
  @payloadcms/ui/shared: 3.67.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:25 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6020
  Available memory (MB): 16384
  Available CPU cores: 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugarea: uiRelated to the admin panel.status: needs-triagePossible bug which hasn't been reproduced yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions