Session does not work (solved)


#1

hi all,

This should be sooo simple, but no clue why it is not working (yes, I know I should better not use session. And yes I have installed the session package)

I have an event clicked, and this event calls a login function. This sets a session which my helper should read, but somehow the helper can’t see the value…

import { Session } from 'meteor/session';

function login(user) {
    console.log('login ', user, Meteor.userId());
    try {
        Session.set('loadingIndicator', 'loading');
        console.log('loading in login function is ', Session.get('loadingIndicator'));
Template.SSBIUsers.helpers({
    loading() {
        console.log('loading is ', Session.get('loadingIndicator'));
        return Session.get('loadingIndicator');
    }
})

the console.log output

loading in login function is  loading
loading in helper is  

Thank you so much for helping me with this dummy question! (I am deeply ashamed :slight_smile: )


#2

No, it still does not work in meteor 1.4.3… (another problem is solved by updating)


#3

Solved… :slight_smile:
For others… javascript is async, so never ever expect code below to be executed next… :blush:

I had Session.set('loadingIndicator', ''); outside my callback…


#4

Usually you do a Session.setDefault() call outside of any of your callbacks.

Also, Meteor.loggingIn() or Accounts.loggingIn() will provide the same functionality, and I believe it’s reactive.