github.com/dbernstein1/tyk@v2.9.0-beta9-dl-apic+incompatible/event_handlers/sample/session_editor.js (about)

     1  // ---- Sample session managing middleware -----
     2  var sessionHandler = new TykJS.TykEventHandlers.NewEventHandler({});
     3  
     4  sessionHandler.NewHandler(function(event, context) {
     5      // You can log to Tyk console output by calloing the built-in log() function:
     6      log("Running Session JSVM Handler");
     7      
     8      // Use the TykGetKeyData function to retrieve a session from the session store
     9      var thisSession = JSON.parse(TykGetKeyData(event.Meta.Key, context.APIID))
    10      log("Expires: " + thisSession.expires)
    11      
    12      // You can modify the object just like with the REST API
    13      thisSession.expires = thisSession.expires + 1000;
    14      
    15      // Use TykSetKeyData to set the key data back in the session store
    16      TykSetKeyData(event.Meta.Key, JSON.stringify(thisSession));
    17      
    18  });
    19  
    20  // Ensure init with a post-declaration log message
    21  log("Session JS event handler initialised");