<commit_before>import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import { Meteor } from 'meteor/meteor';

// Import to load these templates
import '../../ui/layouts/app-layout.js';
import '../../ui/pages/login';
import '../../ui/pages/dashboard.js';
import '../../ui/pages/create-article.js';
import '../../ui/pages/all-articles.js';

const exposed = FlowRouter.group({});

export let redirectAfterLogin = '/';

const loggedIn = FlowRouter.group({
    triggersEnter: [(context, redirect) => {
        if (!Meteor.loggingIn() && !Meteor.userId()) {
            const route = FlowRouter.current();
            if (route.route.name !== 'login') {
                redirectAfterLogin = route.path;
            }
            redirect('/login');
        }
    }]
});

exposed.route('/login', {
    name: 'login',
    action() {
        BlazeLayout.render('appLayout', { main: 'login' });
    }
});

loggedIn.route('/', {
    name: 'dashboard',
    action() {
        BlazeLayout.render('appLayout', { main: 'dashboard' });
    }
});

loggedIn.route('/createArticle', {
    name: 'createArticle',
    action() {
        BlazeLayout.render('appLayout', { main: 'createArticle' });
    }
});

exposed.route('/allArticles', {
    name: 'allArticles',
    action() {
        BlazeLayout.render('appLayout', { main: 'allArticles' });
    }
});

loggedIn.route('/logout', {
    name: 'logout',
    action() {
        Meteor.logout(() => {
            FlowRouter.go(FlowRouter.path('login'));
        });
    }
});<commit_msg>Show /login reactive if user with same session (different tab, same browser) logs out<commit_after>import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';

// Import to load these templates
import '../../ui/layouts/app-layout.js';
import '../../ui/pages/login';
import '../../ui/pages/dashboard.js';
import '../../ui/pages/create-article.js';
import '../../ui/pages/all-articles.js';

const exposed = FlowRouter.group({});

export let redirectAfterLogin = '/';

const redirectIfNotLoggedIn = (redirect) => {
    if (!Meteor.loggingIn() && !Meteor.userId()) {
        const route = FlowRouter.current();
        if (route.route && route.route.name !== 'login') {
            redirectAfterLogin = route.path;
        }
        redirect('/login');
    }
};

Tracker.autorun(function() {
    redirectIfNotLoggedIn((path) => {
        if (FlowRouter.current().route) {
            FlowRouter.go(path);
        }
    });
});

const loggedIn = FlowRouter.group({
    triggersEnter: [(context, redirect) => {
        redirectIfNotLoggedIn(redirect);
    }]
});

exposed.route('/login', {
    name: 'login',
    action() {
        BlazeLayout.render('appLayout', { main: 'login' });
    }
});

loggedIn.route('/', {
    name: 'dashboard',
    action() {
        BlazeLayout.render('appLayout', { main: 'dashboard' });
    }
});

loggedIn.route('/createArticle', {
    name: 'createArticle',
    action() {
        BlazeLayout.render('appLayout', { main: 'createArticle' });
    }
});

exposed.route('/allArticles', {
    name: 'allArticles',
    action() {
        BlazeLayout.render('appLayout', { main: 'allArticles' });
    }
});

loggedIn.route('/logout', {
    name: 'logout',
    action() {
        Meteor.logout(() => {
            FlowRouter.go(FlowRouter.path('login'));
        });
    }
});
{'fraction_non_alphanumeric': 0.1941830624465355, 'fraction_numerical': 0.0, 'mean_word_length': 2.735889243876464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6252772', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1110, 'n_words': 197}