Access control

default discord avatar
Yogesh
2 weeks ago
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
    thisisnotchris
    2 weeks ago

    @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
    kariyngva
    2 weeks ago

    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
    thisisnotchris
    2 weeks ago

    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
    kariyngva
    2 weeks ago

    yeah that's right

  • default discord avatar
    Yogesh
    2 weeks ago

    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
    kariyngva
    2 weeks ago

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

  • default discord avatar
    Yogesh
    2 weeks ago

    I'm creating the public website, anyone can access

  • default discord avatar
    kariyngva
    2 weeks ago

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

  • default discord avatar
    Yogesh
    2 weeks ago

    REST api

  • default discord avatar
    kariyngva
    2 weeks ago

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


    access: {
      read: () => true
    }
  • default discord avatar
    Yogesh
    2 weeks ago

    I used, but it is not working

  • discord user avatar
    jmikrut
    Payload Team
    2 weeks ago

    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
    Yogesh
    2 weeks ago

    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
    thisisnotchris
    2 weeks ago

    @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
    Yogesh
    2 weeks ago

    Thanks a lot guys 🙏


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

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.