ValidationError: The following field is invalid: email, but no email field in collection

default discord avatar
2 weeks ago

Hi Everyone,

I have following user collection which where I am not using authentication in payload cms, rather I have a SvelteKit app where i'm handling auth.

import { CollectionConfig, Field } from 'payload/types'; import {isAdmin, isAdminOrSelf} from '../access/Access'; const Users: CollectionConfig = { slug: 'users', admin: { useAsTitle: 'mobile', }, access: { read: isAdminOrSelf('id'), create: isAdminOrSelf('id'), update: isAdminOrSelf('id'), delete: isAdmin, }, fields: [ { name: 'mobile', type: 'text', required: true, unique: true, label: 'Mobile', }, { name: 'first_name', type: 'text', label: 'First Name', }, { name: 'last_name', type: 'text', label: 'Last Name', }, { name: 'membership', type: 'select', options: [ { label: 'Premium', value: 'premium' }, { label: 'Basic', value: 'basic' }, ], defaultValue: 'basic', }, ] }; export default Users;

But I am getting following error while creating a new record from payload cms admin

ERROR (payload): ValidationError: The following field is invalid: email at create (/Users/anil/Projects/RN/vqard-be/node_modules/payload/src/collections/operations/create.ts:215:11) at processTicksAndRejections (node:internal/process/task_queues:96:5) at createHandler (/Users/anil/Projects/RN/vqard-be/node_modules/payload/src/collections/requestHandlers/create.ts:19:17)

Any pointers will be very helpful. TIA

For authentication, I am using a different collection called AdminUser

After digging a little I found that error is little misleading. This error is being thrown for duplicate email key from mongoose. Somehow mongoose is still validating for duplicate email which is basically null. So I didn’t had any problem for first user

    Open the post
    Continue the discussion in Discord
    Like what we're doing?
    Star us on GitHub!


    Connect with the Payload Community on Discord



    Can't find what you're looking for?

    Get help straight from the Payload team with an Enterprise License.