no docs in Vercel

default discord avatar
akacronos
7 months ago
11

I don't know why, but in vercel I don't get docs from a query but in localhost I do.


And i have another similar collection, and similar queries and I get docs in local and the domain. Does anyone have an idea of why?



This is the query, I get docs in local, but not in vercel


const { data } = await axios.get('/communityMembers', {
    params: {
      where: {
        and: [
          {
            community: {
              equals: {
                value: communityId,
                relationTo: 'community',
              },
            },
          },
          {
            member: {
              equals: userId,
            },
          },
        ],
      },
    },
  });


In other collection I use this other query and works in vercel and local:


const { data } = await axios.get('/visits', {
    params: {
      where: {
        and: [
          {
            activity: {
              equals: {
                value: activityId,
                relationTo: 'activities',
              },
            },
          },
          {
            attendee: {
              equals: userId,
            },
          },
        ],
      },
    },
  });


I deploy the project in digital ocean and the query for

communityMembers

works fine 🫠. I really have no idea of why is not working in Vercel

  • default discord avatar
    Jarrod
    7 months ago

    do you get a response at all? does your axios fn throw an error?

  • default discord avatar
    akacronos
    7 months ago

    yes, but without docs :/



    I have a similar request in another page that works



    The weird things:


    - Works in other similar collection / req


    - Works in local but not in vercel


    - Works in digitalocean app but not in vercel 🫠

    Screenshot_2023-02-17_at_3.02.49_p.m..png
    Screenshot_2023-02-17_at_3.03.08_p.m..png
    Screenshot_2023-02-17_at_3.04.46_p.m..png
    Screenshot_2023-02-17_at_3.04.53_p.m..png
  • default discord avatar
    Jarrod
    5 months ago

    Hmm not really sure 🤔 the only thing different appears to be the HTTP res code 304 vs 200

  • discord user avatar
    jmikrut
    Payload Team
    5 months ago

    is it access control?



    do you have

    read

    access control set to

    () => true

    ? if it is not, then you need to be authenticated by default in order to make that request. 9 times out of 10 this is an access control issue

  • default discord avatar
    akacronos
    5 months ago

    thanks for your answer, and yes, definitely was an access issue. I was using the isAdminOrSelf example from the demo site, assuming that in my case that was going to work, but in my collection, I have a relationship with a user, not the user id. that's why it wasn't working.



    I think what a should do would be something like this


    export const isAdminOrSelf = ({ req: { user } }) => {
      if (user) {
        // If user has role of 'admin'
        if (user.role?.includes('admin')) {
          return true;
        }
    
        return {
          user: {
          relationTo: "users",
          value: user.id,
        };
      }
    
      // Reject everyone else
      return false;
    };
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.