Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor Session Replacement?

Tags:

session

meteor

In the latest Meteor release (version 0.5.8), Session has been removed from the server-side code.

Previously I've used Session to store client-specific variables for the server; what is the replacement for this functionality?

Example case: User One opens a browser, User Two opens a browser. One calls a method on the server setting some token, the other calls a method on the server doing the same. I then need to access this when the client requests something. How do I differentiate between the two?

like image 321
Christian Stewart Avatar asked Mar 13 '13 22:03

Christian Stewart


People also ask

What is session in meteor?

Session provides a global object on the client that you can use to store an arbitrary set of key-value pairs. Use it to store things like the currently selected item in a list.

How do I use Session on meteor?

Sessions are used for saving data while the users are using the app. This data will be deleted when the user leaves the app. In this chapter, we will learn how to set a session object, store some data, and return that data. We will use the basic HTML setup.

What is Meteor API?

What is Meteor? Meteor is a full-stack JavaScript platform for developing modern web and mobile applications. Meteor includes a key set of technologies for building connected-client reactive applications, a build tool, and a curated set of packages from the Node. js and general JavaScript community.


1 Answers

You'll want to save your tokens to a collection in the database.

You could use a Session on the server if you wanted to simply by copying the session package into your application's packages directory and changing its package.js to also load on the server. But a Session is an in-memory data structure, and so won't work if you have multiple server instances; and you wouldn't be able to restart the server without losing your user's tokens.

If you store your tokens in the database they'll persist across server restarts, and will work with a future version of Meteor which is able to scale an application by adding more server instances when needed.

If you need to expire your tokens (so that your collection doesn't grow without bound), you could add a "lastUsed" Date field to your token collection, and periodically remove tokens that haven't been used for longer than your chosen expiration period.

like image 112
Andrew Wilcox Avatar answered Oct 31 '22 05:10

Andrew Wilcox