/server-session

Meteor Server-side Sessions, similar to the typical Client Session

Primary LanguageJavaScriptMIT LicenseMIT

Meteor Server Session

This is a repackaging of Matteo's meteor-server-session package, with several key differences. Namely:

  • Sessions are unique to each connection
  • Sessions are automatically removed when the client closes the connection
  • Sessions can only be set from server, but can be read from client or server

API

Naturally, the API is identical to that of Meteor ServerSession, except that set can only be called from the server.

ServerSession.set(key, value); // Should only be invoked on the server
ServerSession.get(key);
ServerSession.equals(key, expected, identical = true);

You can also define a condition to check against before setting a value:

ServerSession.setCondition(function (key, value)); // Should only be invoked on the server

Use Case

A potential use-case for this package is handling one-time API requests. For instance, you could use the ServerSession to store access tokens (e.g from a server-side route) that expire after the connection is closed. This is especially useful if you are using your Meteor app as an external service for other websites.

Notes

  • Meteor's connection close event doesn't fire when server-side code initiates a hot code reload, so the collection in which the sessions are stored (serversession) might accumulate some dead sessions. This shouldn't happen post-deployment though.
  • This package was made with the intent of learning in mind. Be forewarned that the implementation or use-cases here may not be ideal.

License

MIT, like the original package