<commit_before>import * as t from '../types/auth_types';
import { transaction } from 'mobx';
import { authStore, authFormStore } from '../stores/auth_store';
import { browserHistory } from 'react-router';
import { authSetActions } from '../actions/auth_actions';
import { storeEditTab } from '../actions/base_actions';
import { dispatch } from '../helpers/dispatcher';
import Dashboard from '../components/dashboard/dashboard'
import React, { Component } from 'react';

export default function(action, next) {
  switch(action.type) {
    case t.AUTH_SET_ACTIONS:
      transaction( () => {
        authStore.isActionInit = true;
        authStore.actions = action.payload;
      })
      // now we can render
      if (action.render) {
        action.render();
      }
      browserHistory.push('/main');
      setTimeout( () => {
        var component = <Dashboard />
        dispatch(storeEditTab(null, component, 'Dashboard'))
      }, 1)
      return next(null, action);     
    case t.AUTH_CHECK_TOKEN:
      const token = localStorage.getItem('token');
      if (token) {
        const name = localStorage.getItem('name');
        transaction( () => {
          authStore.authenticated = true;
          authStore.name = name;
          authStore.errorMessage = '';
          dispatch(authSetActions(action.render))
        })
      } else {
        // render but goto home
        action.render();
        browserHistory.push('/');
        //return next(null, action);
      }
      return next(null, action);      
    case t.AUTH_SIGN_IN:
    case t.AUTH_SIGN_UP:
      localStorage.setItem('token', action.payload.token);
      localStorage.setItem('name', action.payload.name);
      transaction( () => {
        authStore.authenticated = true;
        authStore.name = action.payload.name;
        authStore.errorMessage = '';
      });
      dispatch(authSetActions())
      return next(null, action);      
      //return next(null, action);
    case t.AUTH_SIGN_OUT:
      localStorage.removeItem('token');
      localStorage.removeItem('name');
      transaction(() => {
        authStore.authenticated = false;
        authStore.name = '';
        authStore.errorMessage = '';
      });
      return next(null, action);
    case t.AUTH_ERROR:
      transaction(() => {
        if (typeof action.payload === 'object') {
          authStore.errorMessage = action.payload.error;
        } else {
          authStore.errorMessage = action.payload;
        }
        authStore.authenticated = false;
        authStore.name = '';
      });
      browserHistory.push('/signin');
      return next(null, action);
    case t.AUTH_VALIDATE_SIGN_UP:
      store.validateSignUp();
      return next(null, action);
  }
  return next(null, action);
}


<commit_msg>move code to the store<commit_after>import * as t from '../types/auth_types';
import { transaction } from 'mobx';
import { authStore, authFormStore } from '../stores/auth_store';
import { browserHistory } from 'react-router';
import { authSetAuthorizations } from '../actions/auth_actions';
import { storeEditTab } from '../actions/base_actions';
import { dispatch } from '../helpers/dispatcher';
import Dashboard from '../components/dashboard/dashboard'
import React, { Component } from 'react';

export default function(action, next) {
  switch(action.type) {
    case t.AUTH_SET_AUTHORIZATIONS:
      authStore.setAuthorizations(action.payload, action.render)
      break;
    case t.AUTH_CHECK_TOKEN:
      authStore.checkToken(action.render)
      break;
    case t.AUTH_SIGN_IN:
    case t.AUTH_SIGN_UP:
      authStore.signInOrUp(action.payload.token,action.payload.name)
      break;
    case t.AUTH_SIGN_OUT:
      authStore.signOut()
      break;
    case t.AUTH_ERROR:
      authStore.Error(action.payload)
      break;
    case t.AUTH_VALIDATE_SIGN_UP:
      store.validateSignUp();
      break;
  }
  return next(null, action);
}



{'fraction_non_alphanumeric': 0.13004598875830353, 'fraction_numerical': 0.0002554931016862545, 'mean_word_length': 2.6588785046728973, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 10, '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': '4413101', 'n_tokens_mistral': 1120, 'n_tokens_neox': 1131, 'n_words': 239}