Reputation: 83
Are we able to clear PFInstallation data forcefully?
Needed this to recreate another PFInstallation when I want to force logout a user.
Current Problem: New Account is using PFInstallation of old account and New Account can't update the PFInstallation (clearing it when logging out).
Other Possible Solution: Update PFInstallation's ACL through cloud code with the new account's data. Is this possible?
Upvotes: 1
Views: 80
Reputation: 4378
In the beforeSave trigger for the installation, check to see if the user is getting set. If so, turn off public read/write access and give read/write access to that user. When logging out, the user should be removed, and you can return public read/write access.
Parse.Cloud.beforeSave(Parse.Installation, function(request, response) {
var installation = request.object;
if( installation.dirty("user") ) {
var acl = new Parse.ACL();
var user = installation.get("user");
if( user ) {
acl.setPublicReadAccess(false);
acl.setPublicWriteAccess(false);
acl.setReadAccess(user.id, true);
acl.setWriteAccess(user.id, true);
}
else {
acl.setPublicReadAccess(true);
acl.setPublicWriteAccess(true);
}
installation.setACL(acl);
}
response.success();
});
Upvotes: 1