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
do you get a response at all? does your axios fn throw an error?
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 ðŸ«
Hmm not really sure 🤔 the only thing different appears to be the HTTP res code 304 vs 200
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
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
Discord
online
Get help straight from the Payload team with an Enterprise License.