Skip to content

Instantly share code, notes, and snippets.

@wordyallen
Last active April 12, 2016 21:03
Show Gist options
  • Save wordyallen/4ad464c37d3bc632f09da30e485ee7c9 to your computer and use it in GitHub Desktop.
Save wordyallen/4ad464c37d3bc632f09da30e485ee7c9 to your computer and use it in GitHub Desktop.
//actions.js
attemptLogin(){
return (dispatch) =>{
dispatch({type: 'ATTEMPTING_LOGIN'}) //this sets the status on the store through the reducer
ref.authWithOAuthPopup("twitter", function(error, authData) {
if (error) {
console.log("Login Failed!", error);
return false
} else {
return authData
}
})
}
}
......................
// loginContainer.js
const mapDispatchToProps= (dispatch) => ({attemptLogin(){
dispatch(actions.attemptLogin())
}})
const Login = React.createClass({
contextTypes: {
router: React.PropTypes.object.isRequired
},
handleSubmit(){
const {attemptLogin} = this.props
if(attemptLogin()){
this.context.router.replace('entries')
}
},
render (){
return(
<a className="button is-large is-primary control" onClick={this.handleSubmit}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment