Skip to content

Instantly share code, notes, and snippets.

@LazyFatArrow
Last active April 10, 2017 06:08
Show Gist options
  • Save LazyFatArrow/576c6adad891f65870eb9b4f2a3c8aa0 to your computer and use it in GitHub Desktop.
Save LazyFatArrow/576c6adad891f65870eb9b4f2a3c8aa0 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
import configureStore from './store';
import { Provider } from 'react-redux';
import {
BrowserRouter as Router,
Redirect,
Route
} from 'react-router-dom';
import { pathToJS } from 'react-redux-firebase';
import './index.css';
const store = configureStore();
// grab our App and Profile containers
import App from './App/AppContainer';
import Profile from './User/ProfileContainer';
// restricts access to a route for authenticated users only
function PrivateRoute ({component: Component, ...rest}) {
const auth = pathToJS(store.getState().firebase, 'auth');
return (
<Route
{...rest}
render={(props) => auth && auth.uid
? <Component {...props} />
: <Redirect to={{pathname: '/', state: {from: props.location}}} />}
/>
)
}
ReactDOM.render(
<Provider store={store}>
<Router>
<div>
<Route path="/" component={App}></Route>
<PrivateRoute path="/profile" component={Profile} />
</div>
</Router>
</Provider>,
document.getElementById('root')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment