In my react application I have a component currentUserMixin
which I am using for managing user sign in.
I want my LoginComponent
(which shows the login form) to not be visible when a user is already logged in.
After I looked here How to restrict access to routes in react-router? I created this component in currentUserMixin
:
NeedsUnAuthenticatedUser: {
statics: {
willTransitionTo: function(transition) {
if(this.authenticated()) {
transition.abort();
}
}
}
}
My issue is now that I don't know where to add this component.
Should I add it in the main app component like this:
export default class App extends Component {
mixins: [currentUserMixin.NeedsUnAuthenticatedUser]
and this:
<Route path="auth" component={AuthIndex}>
<Route path="login" component={LoginComponent} onEnter={willTransitionTo} />
<Route path="register" component={RegisterComponent} />
</Route>
Or should I put it in the actual login component like this:
export default class LoginComponent extends Component {
mixins: [currentUserMixin.NeedsUnAuthenticatedUser]
So where exactly should I put this mixin?