Store / persist session during server rendering
<p>I came across an issue using following starter repo for react: <a href="https://github.com/choonkending/react-webpack-node" rel="nofollow">react-webpack-node</a></p>

<p>I am ussing <a href="https://developer.mozilla.org/en/docs/Web/API/Window/sessionStorage" rel="nofollow">sessionStorage</a> for authentication purposes and realised that due to server rendering nature of this starter I am unable to access this session data while app is rendering on the server i.e. to protect my routes, I'd expect following to work:</p>

<pre><code>import React from 'react'
import { Route, IndexRoute } from 'react-router'

import App from 'containers/App'
import LoginPage from 'containers/LoginPage'
import DashboardPage from 'containers/DashboardPage'

export default (store) =&gt; {
   const requireAuth = (nextState, replace, callback) =&gt; {
     const token = sessionStorage.getItem('token')
     if (!token) {
       replace({
         pathname: '/login',
         state: { nextPathname: nextState.location.pathname }
       })
     }
     callback()
   }

   const redirectAuth = (nextState, replace, callback) =&gt; {
     const token = sessionStorage.getItem('token')
     if (token) {
       replace({
         pathname: '/'
       })
     }
     callback()
   }

  return (
    &lt;Route path='/' component={App}&gt;
      &lt;IndexRoute component={DashboardPage} /&gt;
      &lt;Route path='/login' component={LoginPage} onEnter={redirectAuth} /&gt;
      &lt;Route path='/dashboard' component={DashboardPage} onEnter={requireAuth} /&gt;
      &lt;Route path='/logout' component={LoginPage} /&gt;
    &lt;/Route&gt;
  )
}
</code></pre>

<p>But it is not and I believe this is due to session being undefined on server.</p>