Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the Current Session Id in Meteor.js

How do you find the current Session Id on the client?

I am able to get what seems like the last session id, not the current session id.

console.log(Meteor.default_connection._lastSessionId)
like image 743
Nyxynyx Avatar asked Jan 13 '14 03:01

Nyxynyx


2 Answers

The wording for this is a bit confusing, but _lastSessionId is the current session id.

It is only called this because if the client is disconnected and seeks to reconnect it wants to re-establish the session with the last session id.

The client would reconnect with a message like this :

{"msg": "connect ", "session": "ERoZSR3R3f8zBQ6Ry", "version": "pre1","support":["pre1"]}

The session uses the lastSessionId value. This is then used to re-establish the previous connection.

This is the only case where a new session id would be assigned on a reconnection. That or the session is expired off the server.

If the server restarts it's cache is refreshed and it wouldn't recognize the session anymore, and a new session id would be assigned.

like image 58
Tarang Avatar answered Nov 18 '22 10:11

Tarang


The Meteor login token by default is stored in local storage (not in cookie).

On the client you could access

token = Meteor._localStorage.getItem('Meteor.loginToken')

On the server, once token is received, use the Accounts api to hash using

Accounts._hashLoginToken(res.req.body.token)

Then, you could validate hashed value against users collection for services.resume.loginTokens.hashedToken field

This hack can be used to build meteor - express integration

Meteor Login Token

like image 25
Faiz Mohamed Haneef Avatar answered Nov 18 '22 11:11

Faiz Mohamed Haneef