You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a class with CLP that only allows one role to create.
Create a user and add to said role.
Run cloud function that creates an object on the class.
Get an error of {code: 119, message: "Permission denied for this action."}
If I use .save(null, { sessionToken: req.user.getSessionToken() }) then the save works, however I would like all saves and queries in cloud code functions to use the requesting users session.
A quick work around I've implemented is to override the Parse.Cloud.define function like so: EDIT: Don't do this. It's bad. Technically this overrides the global Parse JS SDK REST request function on every cloud request. If multiple requests come in at the same time and then handle other requests in promises, the most recent session token will be used on all requests
var originalDefine = Parse.Cloud.define;
Parse.Cloud.define = function(name, originalFunction) {
var newFunction = _generateFunction(name, originalFunction);
originalDefine.apply(this, [name, newFunction]);
}
function _generateFunction(name, originalCloudFunction) {
var newFunction = function(request, response) {
// Override Parse RESTController request to set token
var token = request.user.getSessionToken();
var RESTController = Parse.CoreManager.getRESTController();
var originalRequest = RESTController.request;
RESTController.request = function() {
var options = arguments[3] || {};
options.sessionToken = token;
return originalRequest.apply(this, arguments);
}
return originalCloudFunction.apply(this, arguments);
};
return newFunction;
}
The text was updated successfully, but these errors were encountered:
@mbilling I spent some time looking into this and I've determined there's no viable way to automatically use the requesting user's sessionToken in all requests made from a cloud function.
The cloud functions in the open source Parse Server use a global Parse object (which is the Parse JS SDK) for requests (creates, reads, updates, and deletes). Therefore, if you set a current sessionToken or current user on the JS SDK, then all subsequent or concurrent requests will be made with the most recently set sessionToken.
The only solution to this issue is to include the options { sessionToken: req.user.getSessionToken() } on any and all requests in cloud code that should be made as the requesting user.
Environment Setup
Steps to reproduce
{code: 119, message: "Permission denied for this action."}
If I use
.save(null, { sessionToken: req.user.getSessionToken() })
then the save works, however I would like all saves and queries in cloud code functions to use the requesting users session.A quick work around I've implemented is to override the
Parse.Cloud.define
function like so:EDIT: Don't do this. It's bad. Technically this overrides the global Parse JS SDK REST request function on every cloud request. If multiple requests come in at the same time and then handle other requests in promises, the most recent session token will be used on all requests
The text was updated successfully, but these errors were encountered: