parse-server: Query in Parse Cloud returns "unauthorized" error
The command query.find
always returns error in Parse Cloud. The response is Response Body : {"code":141,"error":"Error: undefined unauthorized"}
.
The request is being done by Swift SDK.
It looks that Parse Cloud can’t access the classes of Parse Server.
What could be possible reasons ?
Parse.Cloud.beforeSave("Message", function(request, response) {
if (!request.object.get("uniqueCode")) {
response.error('A Message must have a uniqueCode.');
} else {
var Message = Parse.Object.extend("Message");
var query = new Parse.Query(Message);
query.equalTo("uniqueCode", request.object.get("uniqueCode"));
query.find({
success: function(results) {
if (results.length > 0) {
response.success();
} else {
response.error("A Message with this uniqueCode already exists.");
}
},
error: function(error) {
response.error("Error: " + error.code + " " + error.message);
}
});
}
});
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 67 (31 by maintainers)
Are you setting any client keys in the ParseServer initialization? (rest, js, client, dotnet)… If so, remove them.
What I missed was the serverURL option. Is it the same for you @leo-one? For me the following works perfectly for local development:
@flovilmart I ran into this issue today for some reason.
I used the parse-server-example fresh out of the box added restAPIKey: ‘rest’ and got error unauthorized using cloud code.
You can fix this by adding javascriptKey: ‘unused’ or pass in clientKey, dotNetKey, restAPIKey to be undefined.
The issue lies with this line
https://github.com/parse-community/parse-server/blob/master/src/middlewares.js#L19
req.get()
is returning undefined but info has some defaultsPLEASE LET ME KNOW HOW I CAN FIX THIS BECAUSE I SPEND 4 DAYS IN IT . I CANT FIX IT
Just thought of something, try to init your parse server with a javascriptKey, cloud code needs it to ‘authenticate’ with the parse server, when the request is sent, if the javascriptKey is not provided, that could be problematic.
Also, does the query work in your case with {useMasterKey: true}?
Just confirming: after removing client_key from Parser Server configuration, everything has worked well (including the triggers). I tested from REST API and Swift SDK.