Skip to content

Instantly share code, notes, and snippets.

@technologythree
Created August 2, 2012 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technologythree/3241480 to your computer and use it in GitHub Desktop.
Save technologythree/3241480 to your computer and use it in GitHub Desktop.
Fix for FB.login() called before FB.init() error
jQuery ->
$.ajax
url: "#{window.location.protocol}//connect.facebook.net/en_US/all.js"
dataType: 'script'
cache: true
window.fbAsyncInit = ->
FB.init(appId: '<%= ENV["FACEBOOK_KEY"] %>', cookie: true, status:true, xfbml:true)
$('#sign_in').click (e) ->
e.preventDefault()
FB.login (response) ->
window.location = '/auth/facebook/callback' if response.authResponse
$('#sign_out').click (e) ->
FB.getLoginStatus (response) ->
FB.logout() if response.authResponse
true
$('body').prepend('<div id="fb-root"></div>')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment