Skip to content

Instantly share code, notes, and snippets.

@jtlindsey
Forked from sammylupt/login.js
Last active March 24, 2017 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtlindsey/311678e3aa52bac1c71e4c3e2399e6de to your computer and use it in GitHub Desktop.
Save jtlindsey/311678e3aa52bac1c71e4c3e2399e6de to your computer and use it in GitHub Desktop.
/*
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