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.

what is the easiest way to access my collections data via API to populate in a react web app?

default discord avatar
olivier_vd2 years ago
5

what is the best way to access my content (collections) to populate my front end web app (React)? Is there some sort of Client to authenticate?

  • default discord avatar
    notchr2 years ago

    Hey

    @688702717279076387

    great question



    Payload has an extensive doc on

    https://payloadcms.com/docs/authentication/overview

    Authentication



    In addition, there is an access control system to fine tune permissions



    A common approach is to generate an API-key for your user



    However, if you create a login form on your frontend and hit the login endpoint for your auth enabled collection...



    Then payload creates a secure cookie automatically on the client that authorizes your users requests



    These should satisfy most use cases



    Let me know if you have more questions

  • default discord avatar
    olivier_vd2 years ago

    Thank you

    @1049775120559898725

    , the API-key looks promising! I'll give that a go 🙂

  • discord user avatar
    jarrod_not_jared
    2 years ago
    @688702717279076387

    really depends on the type of content you want to access. Is it public? protected behind access control/auth?



    you can make fetch requests (rest/gql) to retrieve data, I would say that is probably the simplest. If you have content that you want to restrict based on users and their access to certain data, you can set up access control on collections.



    On the frontend you would have a login form (if you want to have private data). When a user logs in with rest/gql, a cookie will be attached to the request and if you make another request to any of the api endpoints you can use

    credentials: "include"

    on the request and it will send the user along with the request and payload will use that user to authenticate/validate access to certain data.



    James made a nice video on access control if you learn more from that kind of content 🙂

    https://www.youtube.com/watch?v=DoPLyXG26Dg&t=292s
  • default discord avatar
    olivier_vd2 years ago

    it's mainly to fetch the content that is created via the cms (to show on the front-end). Perhaps it's easier then to connect with mongoAtlas directly? This is my first full stack app, so I'm still learning as I go 🙂

  • discord user avatar
    jarrod_not_jared
    2 years ago

    Sure thing! I think that video I linked above would still be super valuable to watch. I do think learning how to use the browsers native

    fetch

    api will also be valuable! 🙂

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.