-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix: user validation error inside the forgotPassword operation in the cases where user had localised fields #12034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…alidation while resetting password
paulpopus
requested changes
Apr 28, 2025
paulpopus
approved these changes
Apr 28, 2025
🚀 This is included in version v3.36.0 |
kendelljoseph
pushed a commit
that referenced
this pull request
May 15, 2025
… cases where user had localised fields (#12034) ### What? So, while resetting the password using the Local API, I encountered a validation error for localized fields. I jumped into the Payload repository, and saw that `payload.update` is being used in the process, with no locale specified/supported. This causes errors if the user has localized fields, but specifying a locale for the password reset operation would be silly, so I suggest turning this into a db operation, just like the user fetching operation before. ### How? I replaced this: ```TS user = await payload.update({ id: user.id, collection: collectionConfig.slug, data: user, req, }) ``` With this: ```TS user = await payload.db.updateOne({ id: user.id, collection: collectionConfig.slug, data: user, req, }) ``` So the validation of other fields would be skipped in this operation. ### Why? This is the error I encountered while trying to reset password, it blocks my project to go further :) ```bash Error [ValidationError]: The following field is invalid: Data > Name at async sendOfferEmail (src/collections/Offers/components/SendEmailButton/index.tsx:18:20) 16 | try { 17 | const payload = await getPayload({ config }); > 18 | const token = await payload.forgotPassword({ | ^ 19 | collection: "offers", 20 | data: { { data: [Object], isOperational: true, isPublic: false, status: 400, [cause]: [Object] } cause: { id: '67f4c1df8aa60189df9bdf5c', collection: 'offers', errors: [ { label: 'Data > Name', message: 'This field is required.', path: 'name' } ], global: undefined } ``` P.S The name field is totally fine, it is required and filled with values in both locales I use, in admin panel I can edit and save everything without any issues. <!-- Thank you for the PR! Please go through the checklist below and make sure you've completed all the steps. Please review the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository if you haven't already. The following items will ensure that your PR is handled as smoothly as possible: - PR Title must follow conventional commits format. For example, `feat: my new feature`, `fix(plugin-seo): my fix`. - Minimal description explained as if explained to someone not immediately familiar with the code. - Provide before/after screenshots or code diffs if applicable. - Link any related issues/discussions from GitHub or Discord. - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Fixes # -->
kendelljoseph
pushed a commit
that referenced
this pull request
May 19, 2025
… cases where user had localised fields (#12034) ### What? So, while resetting the password using the Local API, I encountered a validation error for localized fields. I jumped into the Payload repository, and saw that `payload.update` is being used in the process, with no locale specified/supported. This causes errors if the user has localized fields, but specifying a locale for the password reset operation would be silly, so I suggest turning this into a db operation, just like the user fetching operation before. ### How? I replaced this: ```TS user = await payload.update({ id: user.id, collection: collectionConfig.slug, data: user, req, }) ``` With this: ```TS user = await payload.db.updateOne({ id: user.id, collection: collectionConfig.slug, data: user, req, }) ``` So the validation of other fields would be skipped in this operation. ### Why? This is the error I encountered while trying to reset password, it blocks my project to go further :) ```bash Error [ValidationError]: The following field is invalid: Data > Name at async sendOfferEmail (src/collections/Offers/components/SendEmailButton/index.tsx:18:20) 16 | try { 17 | const payload = await getPayload({ config }); > 18 | const token = await payload.forgotPassword({ | ^ 19 | collection: "offers", 20 | data: { { data: [Object], isOperational: true, isPublic: false, status: 400, [cause]: [Object] } cause: { id: '67f4c1df8aa60189df9bdf5c', collection: 'offers', errors: [ { label: 'Data > Name', message: 'This field is required.', path: 'name' } ], global: undefined } ``` P.S The name field is totally fine, it is required and filled with values in both locales I use, in admin panel I can edit and save everything without any issues. <!-- Thank you for the PR! Please go through the checklist below and make sure you've completed all the steps. Please review the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository if you haven't already. The following items will ensure that your PR is handled as smoothly as possible: - PR Title must follow conventional commits format. For example, `feat: my new feature`, `fix(plugin-seo): my fix`. - Minimal description explained as if explained to someone not immediately familiar with the code. - Provide before/after screenshots or code diffs if applicable. - Link any related issues/discussions from GitHub or Discord. - Add review comments if necessary to explain to the reviewer the logic behind a change ### What? ### Why? ### How? Fixes # -->
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
So, while resetting the password using the Local API, I encountered a validation error for localized fields. I jumped into the Payload repository, and saw that
payload.update
is being used in the process, with no locale specified/supported. This causes errors if the user has localized fields, but specifying a locale for the password reset operation would be silly, so I suggest turning this into a db operation, just like the user fetching operation before.How?
I replaced this:
With this:
So the validation of other fields would be skipped in this operation.
Why?
This is the error I encountered while trying to reset password, it blocks my project to go further :)
P.S The name field is totally fine, it is required and filled with values in both locales I use, in admin panel I can edit and save everything without any issues.