Reputation: 598
I am trying to limit the number of logins from all devices to 1. My approach is to call a cloud function on login to retrieve the number of active sessions for this user and return the result. If the result is greater than one then prompt the user to either
The problem is that the cloud function always returns an empty object.
Note: it doesn't matter if the "equalTo" line is enabled or not, the result is always empty. If I test the code with another class it works.
Parse.Cloud.define("findSessions", function(request, response) {
Parse.Cloud.useMasterKey();
var SessionClass = Parse.Object.extend("Session");
var query = new Parse.Query(SessionClass);
query.equalTo("user", request.user);
query.find({
success: function(results) {
response.success({"count": results.length})
},
error: function(error) {
response.error(error)
}
});
});
Any advice?
Upvotes: 1
Views: 23
Reputation: 598
And of course 10 minutes after posting my question I found the solution (after spending hours before with no success).
The trick is Session is it's own class. The moment I replace
var query = new Parse.Query(SessionClass);
with
Parse.Query(Parse.Session);
everything works.
Another nice trick: by removing the line
Parse.Cloud.useMasterKey();
I already get only the sessions I have access too. No need for filters.
Hope that helps someone with a similar problem.
Upvotes: 1