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

import AnonLayout from './anon-layout.jsx'
import AuthLayout from './auth-layout.jsx'
import CompositionViewLayout from './composition-view-layout.jsx'

import About from './about.jsx'
import CompositionForm from './composition-form.jsx'
import CompositionView from './composition-view.jsx'
import HeroPoolForm from './hero-pool-form.jsx'
import NotFound from './not-found.jsx'

import LocalStorage from '../models/local-storage'
import OverwatchTeamCompsApi from '../models/overwatch-team-comps-api'

function requireAuth(nextState, replace, callback) {
  const api = new OverwatchTeamCompsApi()
  api.getUser().then(json => {
    if (json.auth) {
      LocalStorage.set('battletag', json.battletag)
    } else {
      LocalStorage.delete('battletag')
      replace({
        pathname: '/',
        state: { nextPathname: nextState.location.pathname }
      })
    }
  }).then(callback)
}

function redirectIfSignedIn(nextState, replace, callback) {
  const newPath = `/user${nextState.location.pathname}`

  if (LocalStorage.has('battletag')) {
    const battletag = LocalStorage.get('battletag')
    if (battletag && battletag.length > 0) {
      replace({
        pathname: newPath,
        state: { nextPathname: nextState.location.pathname }
      })
      callback()
      return
    }
  }

  const api = new OverwatchTeamCompsApi()
  api.getUser().then(json => {
    if (json.auth) {
      LocalStorage.set('battletag', json.battletag)
      replace({
        pathname: newPath,
        state: { nextPathname: nextState.location.pathname }
      })
    } else {
      LocalStorage.delete('battletag')
    }
  }).then(callback)
}

const App = function() {
  return (
    <Router history={browserHistory}>
      <Route path="/" component={AnonLayout} onEnter={redirectIfSignedIn}>
        <IndexRoute component={CompositionForm} />
        <Route path="about" component={About} />
      </Route>
      <Route path="/comp" component={CompositionViewLayout}>
        <Route path=":slug" component={CompositionView} />
      </Route>
      <Route path="/user" component={AuthLayout} onEnter={requireAuth}>
        <IndexRoute component={CompositionForm} />
        <Route path="about" component={About} />
        <Route path="hero-pool" component={HeroPoolForm} />
      </Route>
      <Route path="*" component={NotFound} />
    </Router>
  )
}

export default App
<commit_msg>Set auth token in local storage on sign in<commit_after>import { Router, IndexRoute, Route, browserHistory } from 'react-router'

import AnonLayout from './anon-layout.jsx'
import AuthLayout from './auth-layout.jsx'
import CompositionViewLayout from './composition-view-layout.jsx'

import About from './about.jsx'
import CompositionForm from './composition-form.jsx'
import CompositionView from './composition-view.jsx'
import HeroPoolForm from './hero-pool-form.jsx'
import NotFound from './not-found.jsx'

import LocalStorage from '../models/local-storage'
import OverwatchTeamCompsApi from '../models/overwatch-team-comps-api'

function requireAuth(nextState, replace, callback) {
  const api = new OverwatchTeamCompsApi()
  api.getUser().then(json => {
    if (json.auth) {
      LocalStorage.set('authenticity-token', json.authenticityToken)
      LocalStorage.set('battletag', json.battletag)
    } else {
      LocalStorage.delete('authenticity-token')
      LocalStorage.delete('battletag')
      replace({
        pathname: '/',
        state: { nextPathname: nextState.location.pathname }
      })
    }
  }).then(callback)
}

function redirectIfSignedIn(nextState, replace, callback) {
  const newPath = `/user${nextState.location.pathname}`

  if (LocalStorage.has('battletag')) {
    const battletag = LocalStorage.get('battletag')
    if (battletag && battletag.length > 0) {
      replace({
        pathname: newPath,
        state: { nextPathname: nextState.location.pathname }
      })
      callback()
      return
    }
  }

  const api = new OverwatchTeamCompsApi()
  api.getUser().then(json => {
    if (json.auth) {
      LocalStorage.set('authenticity-token', json.authenticityToken)
      LocalStorage.set('battletag', json.battletag)
      replace({
        pathname: newPath,
        state: { nextPathname: nextState.location.pathname }
      })
    } else {
      LocalStorage.delete('authenticity-token')
      LocalStorage.delete('battletag')
    }
  }).then(callback)
}

const App = function() {
  return (
    <Router history={browserHistory}>
      <Route path="/" component={AnonLayout} onEnter={redirectIfSignedIn}>
        <IndexRoute component={CompositionForm} />
        <Route path="about" component={About} />
      </Route>
      <Route path="/comp" component={CompositionViewLayout}>
        <Route path=":slug" component={CompositionView} />
      </Route>
      <Route path="/user" component={AuthLayout} onEnter={requireAuth}>
        <IndexRoute component={CompositionForm} />
        <Route path="about" component={About} />
        <Route path="hero-pool" component={HeroPoolForm} />
      </Route>
      <Route path="*" component={NotFound} />
    </Router>
  )
}

export default App

{'fraction_non_alphanumeric': 0.13909702209414024, 'fraction_numerical': 0.00038424591738712776, 'mean_word_length': 3.334721065778518, 'pattern_counts': {'":': 2, '<': 33, '<?xml version=': 0, '>': 39, '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': '660740', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1572, 'n_words': 320}