Skip to content

Instantly share code, notes, and snippets.

@zaguiini
Created January 5, 2018 00:23
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 zaguiini/18a99781cc268dd31dddfad3ed7c2d5a to your computer and use it in GitHub Desktop.
Save zaguiini/18a99781cc268dd31dddfad3ed7c2d5a to your computer and use it in GitHub Desktop.
(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