How to fix MemberStack not defined and 404 errors when accessing member data in Webflow?

Post author
Starr Wen

Hi,

I am trying to access logged in member data on a page through a custom code snippet on webflow. I tried to use the Memberstack frontend API code and inserted the following into custom code in the footer section. 

MemberStack.onReady.then(async function(member) {
    var metadata = await member.getMetaData()
    // do stuff with members data
})

However, when I run the page I get the following error in console. 

Uncaught ReferenceError: MemberStack is not defined

I am not able to access any data of the logged in user. However, the user is clearly logged in and the page is linked and accessing data since my dynamic text is updated with the user's name. 

Any help would be greatly appreciated!

Comments

2 comments

  • Comment author
    Duncan from Memberstack
    • Edited
    • Official comment

    Hey Starr Wen

    Looks like you're using Memberstack 1.0 code. Please see checkout article to see what's different in 2.0. 

    https://docs.memberstack.com/hc/en-us/articles/7253211946523-Converting-Memberstack-1-0-Code-to-2-0-Code

    Here's the code you're looking for: 

    window.$memberstackDom.getCurrentMember().then(({ data : member }) => {
    
    if(member) {
    let metadata = member.metaData
    // Do stuff with logged in member data here
    }
    })
  • Comment author
    William Sayer

    Hey Duncan from Memberstack,

    I have tried using your solution however am still getting errors. Here are the steps I've done so far:

    1. Added this code to my page header...

    <script src="https://api.memberstack.io/memberstack.js?custom" 
    data-memberstack-id="app_(mycode)"></script>


    2. Have added this code to the </body> custom code section of my webflow site:

    <script>
    window.$memberstackDom.getCurrentMember().then(({ data: member }) => {
      if (member) {
    var memberId = member.id
    console.log(memberId);
      } else {
      }
    })
    </script>


    but I still get console errors, here's a screenshot:

    Seems as though there's a 404 error for the JS library. Any help is hugely appreciated because this is holding up my entire project and there isn't much good documentation out there.

    Kind regards,

    Will 

    0

Please sign in to leave a comment.