2017-12-07 4 views
0

私は現在、私のRailsアプリケーション用のFacebookアカウントキットを実装しています。私はちょうどsmslogin機能を使用します。メールはありません。私は、確認コードを取得し、ポップアップウィンドウにそれを入力し、それが正常に検証されます。ただし、loginCallback関数はそれ以降は実行されません。実際には、実行されるのに数回あります。私はここで本当に挫折しています。なぜなら、コードを使っていることは今ではないからです。誰かがここでいくつかのヒントやヒントを与えることができれば助けになるでしょう。 これは私のログインページのためのコードです:Facebookアカウントキット(API)loginCallbackは実行されません

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 
    ); 
    } 

答えて

0

あなたは、クライアント側のJavaScriptコールバックによる応答を処理する場合は、あなたが追加する必要はありません。 redirectオプション。 redirectオプションは、ログインコールバックを処理するサーバー専用です。したがって

、この構成はあなたの例では、私はちょうど私の質問を更新しました

// 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 
     } 
    ); 
    } 
+0

を動作させる必要があります。リダイレクトオプションを削除しても、loginCallback関数はまだ実行されません。 –

関連する問題