Last active
August 29, 2015 14:17
-
-
Save carl0zen/4d4502de1fdfd5ee5a3b to your computer and use it in GitHub Desktop.
Meteor React LoginWithTwitter Component
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
var LoginWithTwitter = React.createClass({ | |
getInitialState: function() { | |
return {loggedIn: false}; | |
}, | |
login: function (e) { | |
var that = this; | |
Meteor.loginWithTwitter(function() { | |
that.setState({ loggedIn: true }); | |
}); | |
}, | |
logout: function () { | |
var that = this; | |
Meteor.logout(function() { | |
that.setState({ loggedIn: false }); | |
}); | |
}, | |
render: function() { | |
if (this.state.loggedIn) { | |
var twitterUser = Meteor.user().services.twitter; | |
return( | |
<div> | |
<a href={ "https://twitter.com/" + twitterUser.screenName } > | |
<img src={ twitterUser.profile_image_url } />{ twitterUser.screenName } | |
</a> | |
<a onClick={ this.logout }>Logout</a> | |
</div> | |
); | |
} else { | |
return( | |
<a onClick={ this.login }> | |
Login | |
</a> | |
); | |
} | |
} | |
}); | |
React.renderComponent( | |
<LoginWithTwitter />, | |
document.getElementById('login-with-twitter') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment