Last active
August 29, 2015 14:07
-
-
Save rottmann/81b7330f574132e04dbe to your computer and use it in GitHub Desktop.
React-Router with Auth
This file contains hidden or 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
// Router | |
var routes = ( | |
<Routes location="history"> | |
<Route name="index" path="/" handler={App}> | |
<Route name="test" path="/test/" handler={Test} /> | |
</Route> | |
<Route name="login" path="/login/" handler={Login}> | |
</Route> | |
<Redirect to="index" /> | |
</Routes> | |
); | |
React.renderComponent(routes, document.body); | |
// AuthMixin | |
var AuthMixin = { | |
auth: null, | |
statics: { | |
willTransitionTo: function(transition) { | |
if ( ! AuthMixin.auth.isAuthenticated()) { | |
transition.redirect('/login/'); | |
} | |
} | |
} | |
}; | |
module.exports = AuthMixin; |
I am fairly new to React. I am trying to do what i think you are accomplishing here which is to use React Router with a authentication "interceptor" to authenticate a user on each request...I am also using fluxxor but i am having trouble getting the big picture of how this all comes together..
Do you have a more built example that using this gist so that i can gain some context of its use?
thanks for any help
Scott
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AuthMixin.auth is a custom auth object -> e.g. accessing cookies / a database / ...