Sha256: 8aafb5da2831c132bc744529878c2cc92af167e32f9ef9771d03feb63492a76c

Contents?: true

Size: 980 Bytes

Versions: 7

Compression:

Stored size: 980 Bytes

Contents

Spree.ready(function() {
  var appendAuthHeaders = function(xhr, settings) {
    for (var key in Spree.accessTokenData) {
      xhr.setRequestHeader(key, Spree.accessTokenData[key]);
    }
  };

  var updateAuthCredentials = function(ev, xhr, settings) {
    $("#progress").hide();

    var newHeaders = {};

    // set flag to ensure that we don't accidentally nuke the headers
    // if the response tokens aren't sent back from the API
    var blankHeaders = true;

    Spree.accessTokenKeys.forEach(function(key) {
      newHeaders[key] = xhr.getResponseHeader(key);

      if(newHeaders[key])
        blankHeaders = false;
    });

    if(blankHeaders) return;

    for(var key in newHeaders) {
      Spree.accessTokenData[key] = newHeaders[key];
    }

  };

  // intercept requests to the API, append auth headers
  $.ajaxSetup({ beforeSend: appendAuthHeaders });

  // update auth creds after each request to the API
  $(document).ajaxComplete(updateAuthCredentials);
});

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
solidus_backend_devise_token_auth-2.8.0.alpha.8 app/assets/javascripts/spree/backend/devise_token_auth.js
solidus_backend_devise_token_auth-2.8.0.alpha.7 app/assets/javascripts/spree/backend/devise_token_auth.js
solidus_backend_devise_token_auth-2.8.0.alpha.6 app/assets/javascripts/spree/backend/devise_token_auth.js
solidus_backend_devise_token_auth-2.8.0.alpha.5 app/assets/javascripts/spree/backend/devise_token_auth.js
solidus_backend_devise_token_auth-2.8.0.alpha.4 app/assets/javascripts/spree/backend/devise_token_auth.js
solidus_backend_devise_token_auth-2.8.0.alpha.3 app/assets/javascripts/spree/backend/devise_token_auth.js
solidus_backend_devise_token_auth-2.8.0.alpha.2 app/assets/javascripts/spree/backend/devise_token_auth.js