Struggling with Meteor’s Session ID

I need to provide user (session) specific data to unauthorised users. I had a somewhat clear idea how to to it, namely by utilising Meteor’s collections mechanism and use the anonymous user’s session id as a key. But there is no obvious way to access the session id.

I googled like a maniac. Fought some time with different approaches. Wrecked my brain. Found out that the session id is available on the server, in Meteor.publish methods. Finally I came up with this mind-bending solution:

[gist https://gist.github.com/Crenshinibon/6183512]

But it’s absolutely worthless. I knew this right from the beginning, but I was unable to find out the right way. The Gods of Google had left me this morning. I knew it was supposed to be stored somewhere in the client.

Right in the moment I finished and integrated the above solution, I came across the session IDs hidden place:

Meteor.default_connection._lastSessionId

Update: Since Meteor 0.6.5 it is:

Meteor.connection._lastSessionId

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s