Getting session ID in Meteor on startup

Mon Jun 30 2014

This way you can get the current sessions ID on the client, by calling a method on the server.

I had some problems with the Meteor.default_connection._lastSessionId returning null in Meteor.startup, so after some digging around I came up with this.

First define a method on the server.

Meteor.methods({
  getSessionId: function() {
    return this.connection.id;
  }
});

Then call on the client and wait for the response.

Meteor.call("getSessionId", function(err, id) {
  return console.log(id);
});