This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor.subscribe( | |
'server_sessions', | |
amplify.store('session'), // Read from local storage / cookies | |
function() { | |
// The server returns only one record, so findOne will return that record | |
serverSession = new Meteor.Collection('server_sessions').findOne(); | |
// Stores into client session all data contained in server session; | |
// supports reactivity when server changes the serverSession | |
Session.set('serverSession', serverSession); | |
// Stores the server session id into local storage / cookies | |
amplify.store('session', serverSession._id); | |
} | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Do not have this in a model.js file, its scope should be server only | |
ServerSessions = new Meteor.Collection('server_sessions'); | |
Meteor.publish('server_sessions', function(id) { | |
var created = new Date().getTime(); | |
// If no id is passed we create a new session | |
if(!id) { | |
id = ServerSessions.insert({created: created}); | |
} | |
// Load the session | |
var serverSession = ServerSessions.find(id); | |
// If no session is loaded, creates a new one; | |
// id no longer valid | |
if(serverSession.count() === 0) { | |
id = ServerSessions.insert({created: created}); | |
serverSession = ServerSessions.find(id); | |
} | |
return serverSession; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment