<commit_before>import React from 'react';
import {render} from 'react-dom';
import {Router, Route, IndexRoute, browserHistory} from 'react-router';

import {Meteor} from 'meteor/meteor';

import {App} from '../../ui/layouts/app';
import {Index} from '../../ui/pages/index';
import {Info} from '../../ui/pages/information';

/**
 * An onEnter action that specifies that if a user is not logged in or logging in then they must log in and are
 * redirected to a login page. The page they were going to visit is stored in history.
 *
 * @param {Object} next An object defining the next state, provided by Meteor.
 * @param {Function} repl A function specifying a redirection/change, provided by Meteor.
 */
const requireAuth = (next, repl) => {
  if (!Meteor.loggingIn() && !Meteor.userId())
    repl({
      pathname: '/login',
      state: {nextPathname: next.location.pathname}
    });
};

const signInRedirect = (next, repl) => {
  if (Meteor.userId() !== null)
    repl({
      pathname: '/home',
      state: {nextPathname: next.location.pathname}
    });
};

Meteor.startup(() => {
  render(
    <Router history={ browserHistory }>
      <Route path="/" component={ App } onEnter={ signInRedirect }>
        <IndexRoute name="index" component={Index}/>
        <Route name="info" path="/info" component={Info}/>
      </Route>
    </Router><commit_msg>Rename signInRedirect to redirectAuth for consistency, make redirectAuth more general to redirect to a specified location, not just /home<commit_after>import React from 'react';
import {render} from 'react-dom';
import {Router, Route, IndexRoute, browserHistory} from 'react-router';

import {Meteor} from 'meteor/meteor';

import {App} from '../../ui/layouts/app';
import {Index} from '../../ui/pages/index';
import {Info} from '../../ui/pages/information';

/**
 * An onEnter action that requires the user accessing that route to be authenticated. If the user is not authenticated
 * they are redirected to a login page.
 *
 * @param {Object} next An object defining the next state, provided by Meteor.
 * @param {Function} repl A function specifying a redirection/change, provided by Meteor.
 */
const requireAuth = (next, repl) => {
  if (!Meteor.loggingIn() && !Meteor.userId())
    repl({
      pathname: '/login',
      state: {nextPathname: next.location.pathname}
    });
};

/**
 * An onEnter action that specifies that a user should be redirected if they are authenticated.
 *
 * @param {String} to The path to redirect to if user is authenticated
 * @return {Function} The redirecting function that handles redirection to the given path.
 */
const redirectAuth = (to) => (next, repl) => {
  if (Meteor.userId() !== null)
    repl({
      pathname: to,
      state: {nextPathname: next.location.pathname}
    });
};

Meteor.startup(() => {
  render(
    <Router history={ browserHistory }>
      <Route path="/" component={ App } onEnter={ redirectAuth('/home') }>
        <IndexRoute name="index" component={Index}/>
        <Route name="info" path="/info" component={Info}/>
      </Route>
    </Router>
{'fraction_non_alphanumeric': 0.14653207424291761, 'fraction_numerical': 0.0, 'mean_word_length': 3.5646359583952454, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 22, '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': '3809976', 'n_tokens_mistral': 913, 'n_tokens_neox': 899, 'n_words': 322}