CORS issue

default discord avatar
Harkirat Singh
last month
9

I am getting this error when I am trying to hit api/users endpoint 403 error



[12:12:46] ERROR (payload): Forbidden: You are not allowed to perform this action.


at executeAccess (C:\Users\HARKIRAT\OneDrive\Desktop\test payload\node_modules\payload\dist\auth\executeAccess.js:9:23)


at process.processTicksAndRejections (node:internal/process/task_queues:95:5)


at async find (C:\Users\HARKIRAT\OneDrive\Desktop\test payload\node_modules\payload\dist\collections\operations\find.js:38:24)


at async findHandler (C:\Users\HARKIRAT\OneDrive\Desktop\test payload\node_modules\payload\dist\collections\requestHandlers\find.js:19:24)



This is the error I am getting

  • default discord avatar
    notchr
    last month

    Good morning @Harkirat Singh - on your users Collection, do you have access control set?



      access: {
        read: () => true,
        create: () => true,
        update: () => true
      },


    It looks something like this



    And typically is the reason for permission issues like the above error

  • default discord avatar
    Harkirat Singh
    last month

    Hi @notchr, The access control is not set in any of my collection I will set that but I am unable to access Users collection in the buildConfig. The Users collection was prebuilt at the time I initialized the buildConfig the following way



    export default buildConfig({


    // By default, Payload will boot up normally


    // and you will be provided with a base

    User

    collection.


    // But, here is where you define how you'd like Payload to work!


    });



    Can you please confirm me how I can get the Users collection so that I can add access to it

  • default discord avatar
    notchr
    last month

    The Users collection is in your collections folder



    Are you able to locate the Users file?

  • default discord avatar
    Harkirat Singh
    last month

    I have installed payload in a existing express app and In my src/collections folder I do not have Users file. I also tried to find Users file in the require('payload/dist/collections') also but I was unable to find

  • default discord avatar
    notchr
    last month

    What is in your collections folder?

  • default discord avatar
    Harkirat Singh
    last month

    Got resolved Thanks

  • default discord avatar
    streamerd
    4 weeks ago

    this solved my problem

  • default discord avatar
    notchr
    4 weeks ago

    @streamerd Glad that worked! Remember, those are good values for testing, but be cautious of having access settings that are too lax!

  • default discord avatar
    streamerd
    4 weeks ago

    yep it's only read: () => true in my case 😉



    hello. I created a new collection type with just one field (media upload that refers to media collection) in a blank project. I was able to add once record. yet, in the next records I kept seeing an error:



    the following field is invalid: email

     const Testimonials: CollectionConfig = {
        slug: 'testimonials',
        fields: [
            { name: 'image', type: 'upload', relationTo: 'media', required: true }
        ],
        access: {
            read: () => true
          }
    };
    
    export default Testimonials;


    and this is my config:


    export default buildConfig({
      
      admin: {
        user: Users.slug,
      },
      collections: [
        Users,
        Treatments,
        Media,
        Testimonials
      ],
      typescript: {
        outputFile: path.resolve(__dirname, 'payload-types.ts'),
      },
      graphQL: {
        schemaOutputFile: path.resolve(__dirname, 'generated-schema.graphql'),
      },
      plugins: [
        payloadCloud()
      ]
    });


    it is uploading the media but not saving the collection





    [13:16:45] ERROR (payload): ValidationError: The following field is invalid: email
        at create (/....../node_modules/payload/src/collections/operations/create.ts:213:11)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at createHandler (/..../node_modules/payload/src/collections/requestHandlers/create.ts:19:17)


    hey I understood the issue. it only works when auth: true in the CollectionConfig. but to be honest I don't like the fact that there is a need to fill email/password each time creating a new entry

    Screenshot_2023-09-21_at_16.21.53.png
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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