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.

.env file help

default discord avatar
kajdev2 years ago
6

Im working localy and have istaled Payload with next.js who I clone on github.


I have create .env -file as I should, but still I have to be loged in to get fetch from api to work?



My fetch is like this:


useEffect(() => {


setLoading(true);


fetch(

${process.env.NEXT_PUBLIC_SERVER_URL}/api/mat-menyer/

)


.then((res) => res.json())


.then((data) => {


setData(data);


setLoading(false);


console.log(data);


});


}, []);



Do I have to put my inlog to admin in the .env-file?



Thank you so much for this cms! 🙏



Best regards,


Kaj

  • default discord avatar
    notchr2 years ago
    @1102931113317502986

    Hello!



    You may be having issues with fetch for a couple of reasons



    1.) Does the collection or global you're fetching have "read" access controls set?



    2.) If the content you're pulling requires authentication, are you passing "credentials: 'include'" in your fetch request?



    Happy to help troubleshoot

  • default discord avatar
    kajdev2 years ago

    Thanks for answare

    @1049775120559898725

    !



    How do I get "read" access to the control? Bit new to this 🙂

  • default discord avatar
    notchr2 years ago

    Of course!



    Check out access control on collections here:

    https://payloadcms.com/docs/access-control/collections

    each collection has their access operations listed



    const Posts: CollectionConfig = {
      slug: "posts",
      access: {
        create: ({ req: { user } }) => { ... },
        read: ({ req: { user } }) => { ... },
        update: ({ req: { user } }) => { ... },
        delete: ({ req: { user } }) => { ... },
        admin: ({ req: { user } }) => { ... },
      },
    };


    each one is a function that will return a boolean



    to enable public read of a collection, you can do



    const Posts: CollectionConfig = {
      slug: "posts",
      access: {
        read: ({ req: { user } }) => true,
      },
    };
  • default discord avatar
    kajdev2 years ago

    Thank you so much! Now its working without to have to be loged in 👏

  • default discord avatar
    notchr2 years ago

    Happy to help!

  • discord user avatar
    denolfe
    2 years ago

    .env file help

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.