Skip to content

Instantly share code, notes, and snippets.

@mattatcha
Created June 7, 2014 23:47
Show Gist options
  • Save mattatcha/e5032cf64e1a7840108e to your computer and use it in GitHub Desktop.
Save mattatcha/e5032cf64e1a7840108e to your computer and use it in GitHub Desktop.
var App = React.createClass({
mixins: [FluxMixin, StoreWatchMixin("AuthStore"), RoutingContextMixin],
getStateFromFlux: function() {
var flux = this.getFlux();
return {
Auth: flux.store("AuthStore").getState()
};
},
render: function() {
var path = this.getRouting().path;
// Handle login/logged out cases.
if (!this.state.Auth.isLoggedIn) {
this.navigate('/login');
} else if(path === '/login') {
this.navigate('/dashboard');
} else if (path === "/") {
this.navigate('/dashboard');
}
// This is needed to pass the current context to the View.
var View = cloneWithProps(this.props.view, {});
return (
<div>
<Header currentUser={this.state.Auth.currentUser} isLoggedIn={this.state.Auth.isLoggedIn}/>
<div className="container">
{View}
</div>
</div>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment