Setting up a custom redirect other than by Memberstack Answered

Is there any way to set a custom redirect upon login or signup that is not through the Memberstack dashboard (paid plan or account level)?

We are looking to redirect users to certain pages depending on where they login and would love to do that in JS.

Comments

4 comments

  • Comment author
    Chuck Lapointe

    Actually seems like I could create a modified version of this new code snippet by Nicolas Scott?
    https://docs.memberstack.com/hc/en-us/articles/12584131679515--Code-Auto-Open-Checkout-Based-on-URL-Params

    Or I hard code the redirect at the form-level…

    0
  • Comment author
    Chuck Lapointe

    Nevermind… I see I can do this at the form level using :

        <form
          id="wf-form-signup"
          name="wf-form-signup"
          data-name="signup"
          redirect="/my-account?ms=3"
          data-redirect="/my-account?ms=3"
          method="get"
          data-ms-form="login"
          class="form-container"
        >
    Your code snippet is great as well if we don’t want to have to create custom forms for the redirects we want.
    0
  • Comment author
    Colin Alsheimer

    trying to do something similar, only redirect the user to the page they were on after signup or login, using the memberstack modal on webflow. is this possible?

    0
  • Comment author
    Jayess

    Hello Colin 👋🏻

    Great to have you on board 😁 Yes it’s possible with some code.

    So I used ChatGPT to convert 1.0 to 2.0 code, so test it out and let me know if it works.

    Place this code on individual pages, below the MemberStack script.
    Do not add either snippet to your site-wide header and don’t forget to change the url after signup in your memberships to match the page you placed the second code snippet.

    Second part of the code:

    <!--Use this code to save the current page URL and redirect back after signup/login-->
    <script>
      window.$memberstackDom.getCurrentMember().then(({ data: member }) => {
        if (!member) {
          sessionStorage.setItem(‘redirect’, window.location.href);
        }
        // do logged in logic here
      }).catch((e) => {
        console.error(e);
        // do logged out logic here
      });
    </script>Second part of the code:
    <!--Place this on your page after signup/login - must be a hidden page-->
    <script>
      window.$memberstackDom.getCurrentMember().then(function(response) {
        var member = response.data;
        if (!member) {
          sessionStorage.setItem(‘redirect’, window.location.href);
        } else {
          var redirect = sessionStorage.getItem(‘redirect’);
          if (redirect) {
            sessionStorage.removeItem(‘redirect’);
            window.location.replace(redirect);
          }
          // do logged in logic here
        }
      }).catch(function(error) {
        console.error(error);
        // do logged out logic here
      });
    </script> 
    0

Please sign in to leave a comment.