-
-
Save bentooth/4b3e48c1be7cd44b468b586824cf5b58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { connect } from 'react-redux'; | |
import { withRouter, Route, Switch, Redirect } from 'react-router-dom'; | |
import Main from 'containers/Main' | |
import Onboarding from 'containers/Onboarding' | |
import Login from 'containers/Login' | |
class App extends Component { | |
render() { | |
const { auth, password } = this.props; | |
return ( | |
<div> | |
{auth ? | |
<Switch> | |
<PrivateRoute path="/app/main" component={Main} password={password}/> | |
<Route path='/app/login' component={Login} /> | |
<Redirect to='/app/main' /> | |
</Switch> | |
: | |
<Switch> | |
<Route path="/app/onboarding" component={Onboarding} /> | |
<Redirect to='/app/onboarding/hello' /> | |
</Switch> | |
} | |
</div> | |
) | |
} | |
} | |
const PrivateRoute = ({component: Component, password, ...rest}) => ( | |
<Route {...rest} render={(props) => ( | |
password !== '' | |
? <Component {...props} /> | |
: <Redirect to='/app/login' /> | |
)} /> | |
) | |
export default withRouter(connect( | |
state => ({ | |
auth: state.user.isUserAuthenticated, | |
password: state.user.password | |
}) | |
)(App)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment