Parse-SDK-JS: Query condition `equalTo` doesn't work for relation field with `Parse.User`
New Issue Checklist
- I am not disclosing a vulnerability.
- I am not just asking a question.
- I have searched through existing issues.
- I can reproduce the issue with the latest versions of Parse Server and the Parse JS SDK.
Issue Description
In our Cloud functions, we use request.user in a query to filter the results on a Parse.Relation field.
// class schema:
export const MyClassSchema = {
className: 'MyClass',
fields: {
name: { type: 'String', required: true },
users: { type: 'Relation', targetClass: '_User' },
},
classLevelPermissions: {
find: { requiresAuthentication: true },
count: { requiresAuthentication: true },
get: { requiresAuthentication: true },
update: {},
create: {},
delete: {},
protectedFields: {
'*': ['users'],
},
},
};
// in a cloud function which requires user authentication
const query = new Parse.Query('MyClass')
.equalTo('users', request.user);
const result = await query.find(useMasterKeyOption);
Since 3.4.2, this returns an empty list, before it returned the correct list of objects which have request.user in their relation.
However, if I create a new user User pointer with request.user.id, the lookup works fine again.
const user = new Parse.User();
user.id = request.user.id;
const query = new Parse.Query('MyClass')
.equalTo('users', user);
const result = await query.find(useMasterKeyOption);
Another workaround is:
const query = new Parse.Query('MyClass').equalTo('users', request.user.toPointer());
request.user looks fine in the debugger. I also looked at the release notes between 3.4.1 and 3.4.2 but nothing catched my eye.
Steps to reproduce
Use a class schema with relation field to Parse.User and test with a cloud function within a user scope.
Actual Outcome
Empty result set.
Expected Outcome
Result set with entries where user is in the relation.
Environment
Server
- Parse Server version:
5.2.4 - Operating system:
macOS 12.4 - Local host: Node 16 LTS Docker container
- TypeScript
4.6.4
Database
- System (MongoDB or Postgres):
MongoDB - Database version:
5.0.8 - Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc):
Local
Client
- Parse JS SDK version:
3.4.2,3.4.3,3.4.4
Logs
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 29 (14 by maintainers)
So I got around to create a simple Parse Server app with a cloud function to reproduce this issue: https://github.com/stephannielsen/parse-js-bug-1534
Simply switch to an older version of the SDK to get it working.
When using
req['userFromJwt'], the cloud function fails. If you use a session token via header, the cloud function succeeds. Something seems to get lost when usinguserFromJwt.@dblythy Any ideas?
How do you mean that? In our original repo we specify a custom User schema. In my linked test I didn’t, so this does not seem to be an issue here.
We use JWT tokens for authentication and the user is set before as
req['userFromJWT']in our express middleware. I do see the user details in the request, so that seems to work. It is also inferred correctly asParseUser/Parse.Objectas far as I can see but I will check that again.I will also try with
toPointer(). That would be better then creating a new Parse.User object and assigning the id manually as a workaround.