Access control

default discord avatar
Yogesh
6 months 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
    notchr
    6 months 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
    6 months 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
    notchr
    6 months 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
    6 months ago

    yeah that's right

  • default discord avatar
    Yogesh
    6 months 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
    6 months ago

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

  • default discord avatar
    Yogesh
    6 months ago

    I'm creating the public website, anyone can access

  • default discord avatar
    kariyngva
    6 months ago

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

  • default discord avatar
    Yogesh
    6 months ago

    REST api

  • default discord avatar
    kariyngva
    6 months ago

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


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

    I used, but it is not working

  • discord user avatar
    jmikrut
    Payload Team
    6 months 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
    6 months 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
    notchr
    6 months 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
    6 months 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.