Find the Current Session Id in Meteor.js

血红的双手。 提交于 2019-12-23 11:48:32

问题


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)

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/21083248/find-the-current-session-id-in-meteor-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!