Ich implementiere derzeit das Facebook Account Kit für meine Rails-Anwendung. Ich benutze nur die SMS-Funktion, keine E-Mail. Ich habe den Bestätigungscode erhalten, gebe ihn in das Popup-Fenster ein, es wird erfolgreich verifiziert. Die Funktion loginCallback wird danach jedoch nicht ausgeführt. Tatsächlich wird es ein paar Mal ausgeführt. Ich bin hier wirklich frustriert, weil ich jetzt nicht weiß, was mit dem Code passiert, er liegt völlig außerhalb meiner Kontrolle. Es wäre hilfreich, wenn hier jemand Hinweise oder Tipps geben könnte. Diese ist der Code für meine Login-Seite:Facebook account kit (API) loginCallback führt nicht
fb_account_kit.htm.haml:
!!!
%html
%head
%meta{:content => "text/html; charset=UTF-8", "http-equiv" => "Content-Type"}/
%title Passwordless Authentication: Facebook Account Kit
/Include the Account Kit SDK
%script{:src => "https://sdk.accountkit.com/vi_VN/sdk.js"}
%body
.ui.container
= form_tag('https://www.accountkit.com/v1.0/basic/dialog/sms_login/', method: :get, class: 'ui form') do
= hidden_field_tag :authenticity_token, form_authenticity_token
.field
= text_field_tag 'country_code', '+84', {class: 'ui input'}
.field
= text_field_tag 'phone_number', nil, {placeholder: 'phone number', class: 'ui input'}
.field
= button_tag 'Login via SMS', {onclick: 'javascript:smsLogin()', class: 'ui primary button'}
-#Login success form
= form_tag('/login_success', method: :post, class: 'ui form', id: 'login_success') do
= hidden_field_tag 'code'
= hidden_field_tag 'csrf'
:javascript
// initialize Account Kit with CSRF protection
AccountKit_OnInteractive = function(){
AccountKit.init(
{
debug: true,
appId: "myapp_id_goes_here",
state: $('#authenticity_token').val(),
version: "v1.0",
fbAppEventsEnabled: true
}
);
};
// login callback
function loginCallback(response) {
alert('inside loginCallback NOW!!!');
alert('response object: ' + JSON.stringify(response));
if (response.status === "PARTIALLY_AUTHENTICATED") {
document.getElementById("code").value = response.code;
document.getElementById("csrf").value = response.state;
console.log('login_success form is gonna be submitted!!!');
document.getElementById("login_success").submit();
}
else if (response.status === "NOT_AUTHENTICATED") {
alert('authentication failed')
}
else if (response.status === "BAD_PARAMS") {
alert('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},
loginCallback
);
}
Arbeit machen habe ich meine Frage nur aktualisiert. Die Funktion loginCallback wird nicht ausgeführt, nachdem ich die Weiterleitungsoption entfernt habe. –