-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Query with current user in cloud function #1090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I also get zero results in the API Console in Parse Dashboard. This must be related to #1084. |
See my comment on #1084, I think I may have found the source of the issue, although not a fix as yet as not enough time today... |
This is expected. In Node, there is no concept of a current user. You need to be explicit about each call. Try this: Parse.Cloud.define('getSettings', function(req, res) {
var query = new Parse.Query("Settings");
query.find({ sessionToken: req.user.getSessionToken() }).then(function(settings) {
res.success(settings);
}, function(error) {
res.error(error);
});
}); You can also use the master key on individual calls:
|
@gfosco Thanks for the reply. Is this mentioned anywhere in the documentation? If not, it definitely should be. |
It was, may have gone missing... we definitely need to re-add it. |
@gfosco This issue should be mentioned in migration guide. |
Wouldn't it be cool to have some more intuitive option to manage that? I hate to try to remember every time "oh what was that key to make query work for current user?" For example:
|
@gfosco Is it really necessary to include I noticed that I can use Can you think of any way to pass the |
Hi, I have a similar situation. First I set public read/write to false for one of the classes and tested using the parse api-console. It worked as expected. It didn't return any results. I enabled the public read/write. It still didnt work and I have to "use master key". Do I need to re-launch parse-dashboard session for the settings to get enabled? Edited: |
@ian-dowhile this is mentioned here in the parse-server guide: http://docs.parseplatform.org/parse-server/guide/#no-current-user |
@flovilmart I missed that, sorry. Thanks for pointing me in the right direction! |
For implementation related questions or technical support, please refer to the stackoverflow community.
Make sure these boxes are checked before submitting your issue -- thanks for reporting issues back to Parse Server!
Environment Setup
Steps to reproduce
Create one user
curl -X POST -H "X-Parse-Application-Id: f15RG3DbyKXrMEVH1u9HVKGuCynEIwy41VnH7Kuw" -H "Content-Type: application/json" -d '{"username":"digbick","password":"qwerty"}' https://fathomless-earth-52600.herokuapp.com/parse/users
Sample output
{"objectId":"hwoH7ADeBo","createdAt":"2016-03-18T10:33:49.770Z","sessionToken":"r:f84be29e1edc20803b203e3d6c9b2e18"}
Create a private Settings object for this user using an ACL like
"ACL":{"hwoH7ADeBo":{"read":true,"write":true}}
(note the usage of the session token obtained in step 1)curl -X POST -H "X-Parse-Application-Id: f15RG3DbyKXrMEVH1u9HVKGuCynEIwy41VnH7Kuw" -H "X-Parse-Session-Token: r:f84be29e1edc20803b203e3d6c9b2e18" -H "Content-Type: application/json" -d '{"user":{"__type":"Pointer","className":"_User","objectId":"hwoH7ADeBo"}, "saveOriginalPhotos":true, "ACL":{"hwoH7ADeBo":{"read":true,"write":true}}}' https://fathomless-earth-52600.herokuapp.com/parse/classes/Settings
Fetch all Settings objects (using the session token again)
curl -X GET -H "X-Parse-Application-Id: f15RG3DbyKXrMEVH1u9HVKGuCynEIwy41VnH7Kuw" -H "X-Parse-Session-Token: r:f84be29e1edc20803b203e3d6c9b2e18" -H "Content-Type: application/json" -d '{}' https://fathomless-earth-52600.herokuapp.com/parse/classes/Settings
Expect an output as follows
{"results":[{"ACL":{"hwoH7ADeBo":{"read":true,"write":true}},"objectId":"ZFrrUgrgaR","user":{"__type":"Pointer","className":"_User","objectId":"hwoH7ADeBo"},"saveOriginalPhotos":true,"updatedAt":"2016-03-18T10:36:45.017Z","createdAt":"2016-03-18T10:36:45.017Z"}]}
And also, if you fetch all Settings without the session token, that is
curl -X GET -H "X-Parse-Application-Id: f15RG3DbyKXrMEVH1u9HVKGuCynEIwy41VnH7Kuw" -H "Content-Type: application/json" -d '{}' https://fathomless-earth-52600.herokuapp.com/parse/classes/Settings
You should get
{"results":[]}
Which makes sense.
Create a cloud function which fetches all Settings and returns them
Call the
getSettings
cloud function sending the session token as wellcurl -X POST -H "X-Parse-Application-Id: f15RG3DbyKXrMEVH1u9HVKGuCynEIwy41VnH7Kuw" -H "X-Parse-Session-Token: r:f84be29e1edc20803b203e3d6c9b2e18" -H "Content-Type: application/json" -d '{}' https://fathomless-earth-52600.herokuapp.com/parse/functions/getSettings
It returns nothing
{"result":[]}
That is, the current user is not being taken into account when querying objects in cloud code, and so, all queries behave like we're not logged in.
The text was updated successfully, but these errors were encountered: