Maximus S
Maximus S

Reputation: 11125

Is Session in Meteor a misnomer?

Although I started using Meteor extensively only recently, the name "Session" for a Session object in Meteor feels like a misnomer to me. It is very different from how it's conventionally used across the web and I don't understand why it's named that way. Is there a specific reason to this or is it possible to rename it to something more suitable?

Upvotes: 0

Views: 56

Answers (1)

David Weldon
David Weldon

Reputation: 64342

A Session variable is a reactive data source which:

  • can be globally accessed anywhere in your client code
  • will survive a hot code push
  • will not survive a hard reload

I agree that the name is confusing because of the last point. To answer your question, yes you could name it something else if you really wanted to. For example:

client/lib/session.js

NotReallySession = Session;

Then elsewhere in your client code, you could do:

NotReallySession.set('answer', 42);
NotReallySession.get('answer');

However, I'm not sure what you really gain by doing this.

A more attractive solution would be to use a package like persistent-session which modifies the Session api to give you persistence across page refreshes by keeping values in localstorage.

Of particular interest may be the Session.setAuth function, which stores a persistent reactive value which is cleared on logout. In my view, this most closely aligns with the notion of "session" from other contexts.

Upvotes: 2

Related Questions