Skip to content

Instantly share code, notes, and snippets.

@matiasmoya
Created April 8, 2015 18:35
Show Gist options
  • Save matiasmoya/ee8f247301682cd7f430 to your computer and use it in GitHub Desktop.
Save matiasmoya/ee8f247301682cd7f430 to your computer and use it in GitHub Desktop.
facebook login async
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