Payload Cloud Next.js: 403 error… cors?

default discord avatar
Jarrod
7 months ago
10

When you say vs-code is complaining, what do you mean? Like a type error? or an error in a console?



I don't see any type errors when I pull down a fresh copy of that repo

  • default discord avatar
    Nball
    7 months ago

    Yes, type errors in vs code and 500 error in the browser console. I also did not see errors in the fresh pull of the auth example. Not sure why I'm getting them with such a bone simple start.





    Payload Cloud Next.js: 403 error… cors?



    Accidentally deleted the original message, oops! I believe the cors setting is not allowing Next.js to query the REST API. After dealing with the earlier issue (which was as simple as adding required: true to the slug in the post collection) I am now getting a 403 "You are not allowed to perform this action." response when calling a test function like this:



    async function test() {
    const getAllPosts: { docs: Post[] } = await fetch(
    ``${process.env.NEXT_PUBLIC_CMS_URL}/api/posts?limit=100``,
    ).then((res) => res.json());
    console.log(getAllPosts);
    }
    test();
    image.png
  • default discord avatar
    Jarrod
    7 months ago

    ok. Are you logged in? Is this public content? If it is meant to be public, you will need to adjust the read access on that collection

  • default discord avatar
    Nball
    7 months ago

    This is in the config:


    cors: [process.env.PAYLOAD_PUBLIC_CMS_URL, process.env.PAYLOAD_PUBLIC_SITE_URL].filter(Boolean),

    Both env vars output correctly, in this case:

    http://localhost:3000

    and

    http://localhost:8000
  • default discord avatar
    Jarrod
    7 months ago
    read: () => true
  • default discord avatar
    Nball
    7 months ago

    Aha! This will be public content, yes.



    That did it! Thank you so much @Jarrod

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.