Created
April 8, 2015 18:35
-
-
Save matiasmoya/ee8f247301682cd7f430 to your computer and use it in GitHub Desktop.
facebook login async
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
jQuery -> | |
$('body').prepend('<div id="fb-root"></div>') | |
$.ajax | |
url: "#{window.location.protocol}//connect.facebook.net/en_US/all.js" | |
dataType: 'script' | |
cache: true | |
window.fbAsyncInit = -> | |
FB.init(appId: '<%= ENV["FACEBOOK_APP_ID"] %>', cookie: true) | |
$('#sign_in').click (e) -> | |
e.preventDefault() | |
FB.login (response) -> | |
window.location = '/auth/facebook/callback' if response.authResponse #we need to handle the response data asynchronously here :D | |
#maybe a $.get request? like $.get '/auth/facebook/callback', -> alert 'do something with the devise response here!' | |
$('#sign_out').click (e) -> | |
FB.getLoginStatus (response) -> | |
FB.logout() if response.authResponse | |
true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment