Last active
March 24, 2017 00:48
-
-
Save TimCannady/a94e622e9102c42a35df80bfa517df35 to your computer and use it in GitHub Desktop.
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
// This comma at the end of line-12 does not appear in the docs (https://developers.facebook.com/docs/accountkit/webjs). | |
// Omitting the comma results in the following console error: 'Uncaught SyntaxError: Unexpected identifier'. | |
// Adding the comma results in AccountKit'ing success! (assuming all other constraints are met) | |
<script> | |
// initialize Account Kit with CSRF protection | |
AccountKit_OnInteractive = function(){ | |
AccountKit.init( | |
{ | |
appId:"{{FACEBOOK_APP_ID}}", | |
state:"{{csrf}}", | |
version:"{{ACCOUNT_KIT_API_VERSION}}", // <~~~~ | |
fbAppEventsEnabled:true | |
} | |
); | |
}; | |
// login callback | |
function loginCallback(response) { | |
if (response.status === "PARTIALLY_AUTHENTICATED") { | |
var code = response.code; | |
var csrf = response.state; | |
// Send code to server to exchange for access token | |
} | |
else if (response.status === "NOT_AUTHENTICATED") { | |
// handle authentication failure | |
} | |
else if (response.status === "BAD_PARAMS") { | |
// handle bad parameters | |
} | |
} | |
// phone form submission handler | |
function smsLogin() { | |
var countryCode = document.getElementById("country_code").value; | |
var phoneNumber = document.getElementById("phone_number").value; | |
AccountKit.login( | |
'PHONE', | |
{countryCode: countryCode, phoneNumber: phoneNumber}, // will use default values if not specified | |
loginCallback | |
); | |
} | |
// email form submission handler | |
function emailLogin() { | |
var emailAddress = document.getElementById("email").value; | |
AccountKit.login( | |
'EMAIL', | |
{emailAddress: emailAddress}, | |
loginCallback | |
); | |
} | |
</script> |
Author
TimCannady
commented
Mar 10, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment