ESLint Unexpected Session statement


#1

Not sure why but when I use session, I’m getting the ESLint error (meteor/no-session) “Unexpected Session statement”

Here’s a sample:

import { Session } from 'meteor/session';
const redirect = Session.get('redirect');

#2

Are you accessing the session outside the context of a function?


#3

I believe sessions are frowned upon using the meteor eslint plugin.


#4

Yep. From the docs:

This rule prevents any usage of Session. Session variables live in a global namespace, which is bad practice. reactive-dict should be used instead.

You can disable this (and any other eslint rule by adding the following to rules dictionary in eslint config:

        "meteor/no-session": [
            0
        ],

#5

I’m using session in my Accounts.onLogin to handle redirects to the forwarding page after login:

Accounts.onLogin(()=> {
    const redirect = Session.get('redirect');

#6

In this case it makes sense, so I would just ignore the warning.