1
votes

I need to know about the Sessions.Actually we using default sessions like session.set(key,value) and session.get(key). In this default session are cleared some cases like refresh and etc.

First i am using meteor add u2622:persistent-session Pkg.Use of this pkg gets one error i.e "Uncaught Error: Meteor does not currently support objects other than ObjectID as ids".

To overcome those problems to use amplify Sessions. But did one sample to using amplify Sessions as shown below code :

Js Code :

Messages = new Meteor.Collection("messages");
if (Meteor.isClient) {


  var AmplifiedSession = _.extend({}, Session, {
    keys: _.object(_.map(amplify.store(), function (value, key) {
      return [key, JSON.stringify(value)];
    })),
    set: function (key, value) {
      Session.set.apply(this, arguments);
      amplify.store(key, value);
    }
  });


  // counter starts at 0
  Session.setDefault('counter', 0);
  AmplifiedSession.set('no', 1);




  Template.hello.helpers({
    counter: function () {
      return Session.get('counter');
    }
  });

  Template.hello.helpers({
    no: function () {
      return AmplifiedSession.get('no');
    }
  });

  Template.hello.events({
    'click button': function () {
      // increment the counter when button is clicked
      console.log("Btn Clicked");
      Session.set('counter', Session.get('counter') + 1);
      AmplifiedSession.set('no',AmplifiedSession.get('no') + 1);
    }
  });
}

if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup


  });
}

Even not working.amplify Sessions also cleared at the time of Refresh.I didn't get any idea about this.So please suggest me what to do for this.

Thanks in Advance.

2

2 Answers

0
votes

Try this package on atmosphere and let me know if it helped.

meteor add u2622:persistent-session

-1
votes

In this particular example, on every page load, you are running AmplifiedSession.set('no', 1);, therefore setting 'no' to be 1. This is why on page refreshes, 'no' is getting set to 1. Remove this line, and then change this line AmplifiedSession.set('no',AmplifiedSession.get('no') + 1); to set the value of 'no' if it does not exist.