-
-
Save jtlindsey/311678e3aa52bac1c71e4c3e2399e6de 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
/* | |
from | |
https://medium.com/the-many/adding-login-and-authentication-sections-to-your-react-or-react-native-app-7767fd251bd1#.z5fpuv78y | |
*/ | |
function loggedIn() { | |
// ... | |
} | |
function requireAuth(nextState, replace) { | |
if (!loggedIn()) { | |
replace({ | |
pathname: '/login' | |
}) | |
} | |
} | |
function routes() { | |
return ( | |
<Route path="/" component={App}> | |
<Route path="login" component={Login} /> | |
<Route path="logout" component={Logout} /> | |
<Route path="checkout" component={Checkout} onEnter={requireAuth} /> | |
</Route> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment