I have a node.js express app using the Parse Javascript SDK and Parse-Server.
I've set everything up according to the guide but the JS SDK is not working.
I'm getting {error:unauthorized}
. I can access my server with REST API just fine but not from within the app using the JS SDK.
I read that you have to specify useMasterKey = true
for all operations with Parse-Server so:
var User = Parse.Object.extend('_User');
var query = new Parse.Query(User);
query.useMasterKey = true;
query.find().then( function(results) {
console.log(results);
},
function(error) {
console.log(JSON.stringify(error));
});
Should return the same data that this curl does (right?):
curl -X GET \
-H "X-Parse-Application-Id: myAppId" \
-H "X-Parse-Master-Key: myMasterKey" \
http://localhost:1337/parse/classes/_User
Alas, this is not the case.
Same error message when I try to run the default cloud code function:
Parse.Cloud.run('hello').then( function(response) {
console.log(response);
},
function(error) {
console.log(JSON.stringify(error));
});
Any ideas that might help? Thanks.
Got it!
What did it for me were these lines in my Express app
var Parse = require('parse/node').Parse;
Parse.initialize('app_id', 'js_key','master_key');
Parse.serverURL = 'serverURL';
Parse.Cloud.useMasterKey();
After these lines, any kind of call that requires Cloud Code usage or Parse usage were authorized
My problem was inexperience:
I am using body-parser and had the app set up to use that module's raw
, json
, text
, and urlencoded
middleware functions.
I only needed the urlencoded
option. I removed the others and the JS SDK started working fine. Somehow, the other functions were interfering with the SDK.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.