Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Payload Cloud Next.js: 403 error… cors?

5

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
    nballlast year

    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();
  • 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
    nballlast year

    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
  • read: () => true
  • default discord avatar
    nballlast year

    Aha! This will be public content, yes.



    That did it! Thank you so much

    @281120856527077378
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.