Created
January 5, 2018 00:23
-
-
Save zaguiini/18a99781cc268dd31dddfad3ed7c2d5a to your computer and use it in GitHub Desktop.
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
(function(d, s, id){ | |
var js, fjs = d.getElementsByTagName(s)[0] | |
if (d.getElementById(id)) {return} | |
js = d.createElement(s); js.id = id | |
js.src = "//connect.facebook.net/en_US/sdk.js" | |
fjs.parentNode.insertBefore(js, fjs) | |
}(document, 'script', 'facebook-jssdk')) | |
window.fbAsyncInit = function() { | |
FB.init({ | |
appId: 'APPID', | |
status: true, | |
xfbml: true, | |
version: 'v2.9' | |
}) | |
} | |
// Receive message from webview | |
window.onMessage = function(data) { | |
// finish facebook authentication flow | |
} | |
// Web Facebook Login | |
function loginFacebook(response) { | |
if(response && response.status !== 'connected') { | |
return alert('denied') | |
} else if(response && response.status === 'connected') { | |
return alert('logged in') | |
} | |
FB.getLoginStatus(function(response) { | |
if(response.status !== 'connected') { | |
FB.login(loginFacebook) | |
} else { | |
alert('logged in') | |
} | |
}) | |
} | |
function triggerLogin(platform) { | |
switch(window.isNative) { | |
case 'android': | |
window.postMessage(platform) | |
break | |
case 'ios': | |
window.webkit.messageHandlers.reactNative.postMessage(platform) | |
break | |
default: | |
window[platform]() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment