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.

no docs in Vercel

default discord avatar
akacronos2 years ago
5

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

  • discord user avatar
    jarrod_not_jared
    2 years ago

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

  • default discord avatar
    akacronos2 years 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 🫠

  • discord user avatar
    jarrod_not_jared
    2 years ago

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

  • discord user avatar
    jmikrut
    2 years 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
    akacronos2 years 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;
    };
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.