Last active
January 7, 2016 00:30
-
-
Save codedmart/a74334202e06e0367d70 to your computer and use it in GitHub Desktop.
This file contains 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
import React from 'react'; | |
import { RedirectIfLoggedIn } from '../common/auth'; | |
import ReactAbstractComponent from '../lib/ReactAbstractComponent'; | |
class Login extends ReactAbstractComponent { | |
handleLoginSubmitted = (user) => { | |
const {login} = this.context.actions; | |
login(user); | |
} | |
render() { | |
// ... some content | |
} | |
}; | |
export default RedirectIfLoggedIn(Login); |
This file contains 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
import React, {PropTypes} from 'react'; | |
const RedirectIfLoggedIn = (Component) => class extends ReactAbstractComponent { | |
checkCurrentUser = () => { | |
const currentUser = this.getCurrentUser(); | |
if (currentUser) this.context.router.transitionTo('/'); | |
} | |
componentWillMount() { | |
this.checkCurrentUser(); | |
} | |
componentWillUpdate() { | |
this.checkCurrentUser(); | |
} | |
render() { | |
return <Component {...this.props} {...this.state}/>; | |
} | |
}; | |
export default RedirectIfLoggedIn; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment