import React from 'react';
import { Route, IndexRoute } from 'react-router';
import $ from 'jQuery';

import CoreLayout from 'layouts/CoreLayout';
import HomeView from 'views/HomeView';
import ResumeView from 'views/ResumeView';
import UserFormView from 'views/UserFormView';
import AboutView from 'views/AboutView';
import SecretView from 'views/SecretView';


function requireAuth(nextState, replaceState) {
  // NOTE: will change url address when deployed
  $.ajax({
    url: 'http://localhost:3000/authentication',
    async: false,
    type: 'POST',
    contentType: 'application/json',
    success: (data) => {
      if (data.Auth === false) {
        replaceState({
          nextPathname: nextState.location.pathname
        }, '/');
      }
    },
    error: (xhr, status, err) => console.error(err)
  });
}

export default (
  <Route path='/' component={CoreLayout}>
    <IndexRoute component={ResumeView} />
    <Route path='/userform' component={UserFormView} />
    <Route path='/resume' component={ResumeView} />
    <Route path='/about' component={AboutView} />
    <Route path='/secretpage' component={SecretView} onEnter={requireAuth} />
  </Route>
);

@@ -889,36 +889,34 @@
 oute component=%7B
-Resu
+Ho
 meView%7D /%3E%0A    %3C

Update default view user renders due to Melody