Search code examples
parse-server

How to determine timestamp of last API request by user in parse server?


Is there a way to determine the timestamp of the last app launch or log the timestamp the last API request from a user on parse server, on the server side without adding code to the client?


Solution

  • To do this without modifying the client, you could think of a request your clients always perform, like a find query and then set a hook on your server like this one from the docs.

    Parse.Cloud.beforeFind('MyObject', function(req) {
      let query = req.query; // the Parse.Query
      let user = req.user; // the user
      let triggerName = req.triggerName; // beforeFind
      let isMaster = req.master; // if the query is run with masterKey
      let isCount = req.count; // if the query is a count operation (available on parse-server 2.4.0 or up)
      let logger = req.log; // the logger
      let installationId = req.installationId; // The installationId
    });
    

    Then just persist the data you want somewhere like the user model and save it.