Skip to content

Instantly share code, notes, and snippets.

@nelix
Last active August 29, 2015 14:21
Show Gist options
  • Save nelix/99d4a3dad9b27e79ca1b to your computer and use it in GitHub Desktop.
Save nelix/99d4a3dad9b27e79ca1b to your computer and use it in GitHub Desktop.
const Authenticated = function(isAuthenticated) {
return React.createClass({
displayName: 'Authenticated',
statics: {
willTransitionTo(transition) {
if (!isAuthenticated()) {
transition.redirect('login');
}
},
},
mixins: [Router.Navigation],
componentDidUpdate() {
if (!isAuthenticated()) {
this.transitionTo('/login');
}
},
render() {
if (!isAuthenticated()) {
return <span>'Redirecting to login'</span>;
}
return (
<Router.RouteHandler
{...this.props}
/>
);
},
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment