Jump to content

Get Current Logged-In Customer Details

Recommended Posts

I am trying to add embedded content to a site, but I need to make an AJAX request to get the embed URL for the iframe. This request needs to provide a unique identifier for the current logged in customer. Basically like this:
 

(function() {

  var fd = new FormData();
  fd.append('userId', /* somehow get a stable customer id? */);

  var xhr = new XMLHttpRequest();
  xhr.open('POST', myApiUrl, true);
  xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xhr.onreadystatechange = function() {
     // ...status checks...
     var { uri } = JSON.parse(xhr.responseText);
     var frame = document.createElement('iframe');
     frame.src = uri;
     document.getElementById('myTargetElement').appendChild(frame);
  }
  xhr.send(fd);

})();

Any suggestions? I noticed that window.Static.SQUARESPACE_CONTEXT.authenticatedAccount provides all of the info that I need, but doesn't appear to be populated for member accounts.

Link to comment
  • Replies 1
  • Views 758
  • Created
  • Last Reply

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.