Skip to content

Instantly share code, notes, and snippets.

@TimCannady
Last active March 24, 2017 00:48
Show Gist options
  • Save TimCannady/a94e622e9102c42a35df80bfa517df35 to your computer and use it in GitHub Desktop.
Save TimCannady/a94e622e9102c42a35df80bfa517df35 to your computer and use it in GitHub Desktop.
// 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>
@TimCannady
Copy link
Author

screen shot 2017-03-10 at 3 26 58 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment