How to delay login redirect in Memberstack 2.0 until member page automation completes?

Post author
MARTIN ALONSO

Hello, I have recently migrated to Memberstack 2.0.

Previously, I had the following script on my welcome page, which redirected members to their member page after signup:

<script>
var Webflow = Webflow || [];
Webflow.push(function() {
  MemberStack.onReady.then(function(member) {
    if(member.memberPage){
      window.location.replace(member.memberPage);
    } else {
      setTimeout(function() { location.reload(true); }, 3000);
    }
  })
});
</script>

However, this script no longer works in Memberstack 2.0.

I've set up an automation (in make) to create the member page and configure it in the login redirect. This automation takes around 10 seconds to complete. If the redirect happens too quickly, the login redirect page may not yet be created or configured.

Could someone help me update the script to work as it did in 1.0?

Comments

1 comment

  • Comment author
    Duncan from Memberstack
    • Edited

    Absolutely, I can help you with that! 😊 Since you're using Memberstack 2.0 and have an automation that takes some time to create the member page, we can modify your script to include a delay before checking for the member page. This way, it will give your automation enough time to complete.

    Here's an updated version of your script:

    <script>

    var Webflow = Webflow || [];Webflow.push(function() {  

    // Ensure Memberstack is fully loaded before executing the code

     window.$memberstackDom.getCurrentMember().then(({ data: member }) => {    

    if (member) {      // Redirect to the member-specific page      window.location.replace(member.loginRedirect);    } else {      // If no memberPage is set, you can choose to reload or redirect elsewhere      setTimeout(function() { location.reload(true); }, 10000);    }  });});

    </script>

    Changes Made:

    1. Added a setTimeout: This waits for 10 seconds before checking if the `memberPage` exists. This should give your automation enough time to create and configure the member page.
    2. Retained the original functionality: If the member page is not available after the delay, it will reload the page after 3 seconds.

    Feel free to adjust the delay time if needed! Let me know if this works for you or if you need further assistance. 😊

    0

Please sign in to leave a comment.