Saving attributes on a user fetched from a query (i.e. not on the currentUser)

前端 未结 2 1886
我在风中等你
我在风中等你 2020-12-08 09:06

I am interested in saving attributes to users in the database based on actions that are performed by my currentUser. Based on the following code, I get the err

2条回答
  •  鱼传尺愫
    2020-12-08 09:25

    If you want to update a user that is not currently the logged in user you will need to call Parse using the master-key.

    You can do this from CloudCode for example;

    Parse.Cloud.define('editUser', function(request, response) {
        var userId = request.params.userId,
            newColText = request.params.newColText;
    
        var User = Parse.Object.extend('_User'),
            user = new User({ objectId: userId });
    
        user.set('new_col', newColText);
    
        Parse.Cloud.useMasterKey();
        user.save().then(function(user) {
            response.success(user);
        }, function(error) {
            response.error(error)
        });
    });
    

    and calling it from your iOS project;

    [PFCloud callFunction:@"editUser" withParameters:@{
        @"userId": @"someuseridhere",
        @"newColText": @"new text!"
    }];
    

提交回复
热议问题