Getting a Timestamp from the Server

This simple sample code will return a timestamp from the server to the client if the logged-in user executes the code.

This server code is synchronous.

function server_time(params, context) {
  // If the current user executed this server code
  if (context.getAccessToken()) {
    // Return a timestamp.
  } else {
    return "Sorry, we don't allow an anonymous user to get a timestamp";

This code uses the getAccessToken() method to get the access token of the user from the context argument. If a valid access token exists, then the code returns a timestamp.