Meteor JS Uncaught ReferenceError: session not defined

I have a very simple event configured in the \ client \ main.js file:

Template.hello.events({ 'click button': function () { Session.set('selectedPlayer', 'session value test'); Session.get('selectedPlayer'); var selectedPlayer = Session.get('selectedPlayer'); console.log(selectedPlayer); } }); 

However, whenever I click the button, the console says "Uncaught ReferenceError: Session is not defined" on the line with the first call to Session.set .

Other similar issues blame this on the fact that the session only works on the client, not on the server, but as far as I know, everything in the client folder is automatically on the client side.

+6
source share
2 answers

I have found the answer.

It seems that the session is no longer part of the standard meteor packet. You need to run meteor add session for it to work.

+23
source

Add a session to your application, run this command in your terminal,

 meteor add session 

The import operation is used to load them,

 import { Session } from 'meteor/session' 
0
source

All Articles