Access control

default discord avatar
Yogeshlast year
28

When I try to access my ReactJS website to different browser, then it's not working. Need to login Payload admin portal, then its working fine.


How can I access my website without passing any credentials or login in different browser.


I'm using the payload:1.6.32 version.

  • default discord avatar
    notchrlast year

    @Yogesh Good morning! This is likely happening because you are not bringing the cookie stored upon a sucessful login with you to the other browser



    You would have to somehow bring the cookie over to maintain your session as far as I know



    I can imagine some workarounds in my head, but not sure what your end goal is

  • default discord avatar
    kariyngvalast year

    On your collection you can set the

    access

    object to allow read by any one i.e.


      access: {
        read: true,
      }

    The

    template-website

    repo on the payload github has some examples of this along with a helper.

  • default discord avatar
    notchrlast year

    Oh I thought they meant they weren't staying logged in



    Yeah, this is an access control issue then



    @kariyngva Doesn't read need to be a function that returns true?



    access: {
      read: () => true
    }
  • default discord avatar
    kariyngvalast year

    yeah that's right

  • default discord avatar
    Yogeshlast year

    First of all thanks to all


    How I can access my website without login.


    Or how I can provide the public access, so anyone can be access



    I used this already, it's working only logged in user which we have gave to access

  • default discord avatar
    kariyngvalast year

    I'm afraid I don't follow what it is exactly you want to do.

  • default discord avatar
    Yogeshlast year

    I'm creating the public website, anyone can access

  • default discord avatar
    kariyngvalast year

    yeah, how are you reading the data from Payload? REST api, graphql or local?

  • default discord avatar
    Yogeshlast year

    REST api

  • default discord avatar
    kariyngvalast year

    if you have the collection set up like so you shouldn't need authentication 🤷‍♂️


    access: {
      read: () => true
    }
  • default discord avatar
    Yogeshlast year

    I used, but it is not working

  • discord user avatar
    jmikrut
    last year

    make sure you add read access control like the above to each of your collections that you need to retrieve as an unauthenticated user



    this is 100% the issue as reported above

  • default discord avatar
    Yogeshlast year

    Yes sure, I will check that way. Thanks a lot



    Hi @jmikrut Good morning, I used this way but it is not working


    please check below screenshot



    This is my payload.config.ts file



    Could you help me on that?

    Screenshot_from_2023-05-18_20-07-32.png
    Screenshot_from_2023-05-18_20-13-43.png
  • default discord avatar
    notchrlast year

    @Yogesh Nothing seems odd in those SS



    Which part is not working?



    Setting the "read" access control should have made the collection publicly accessible



    In addition, since you have an upload field, I think you also need to set the access control on your Media Collection, assuming that content should also be publicly visible

  • default discord avatar
    Yogeshlast year

    Thanks a lot guys 🙏


    I missed the provide access to media collection. Now it is working

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

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