From 4f12ac82505c952af7f0c88b01195c3985daddfc Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Wed, 22 Jan 2025 00:19:06 -0700 Subject: [PATCH] fix: browser validation error when visiting account page (#10717) Fixes error when visiting account page: ![CleanShot 2025-01-21 at 23 58 48@2x](https://github.com/user-attachments/assets/01502702-319f-46fd-9197-b345eab7fc86) --- packages/payload/src/fields/validations.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/payload/src/fields/validations.ts b/packages/payload/src/fields/validations.ts index 8e13b70afc2..c03d2aee66c 100644 --- a/packages/payload/src/fields/validations.ts +++ b/packages/payload/src/fields/validations.ts @@ -166,7 +166,7 @@ export const email: EmailFieldValidation = ( { collectionSlug, req: { - payload: { collections }, + payload: { collections, config }, t, }, required, @@ -174,7 +174,9 @@ export const email: EmailFieldValidation = ( }, ) => { if (collectionSlug) { - const collection = collections?.[collectionSlug]?.config + const collection = + collections?.[collectionSlug]?.config ?? + config.collections.find(({ slug }) => slug === collectionSlug) // If this is run on the client, `collections` will be undefined, but `config.collections` will be available if ( collection.auth.loginWithUsername && @@ -211,7 +213,9 @@ export const username: UsernameFieldValidation = ( let maxLength: number if (collectionSlug) { - const collection = collections?.[collectionSlug]?.config + const collection = + collections?.[collectionSlug]?.config ?? + config.collections.find(({ slug }) => slug === collectionSlug) // If this is run on the client, `collections` will be undefined, but `config.collections` will be available if ( collection.auth.loginWithUsername &&