Redirect after login to previous page

Hi, I have a question on the redirection, not sure if I am doing it correctly but here’s my code:

I put this code at https://roomindigo.webflow.io/services

<!--Use this code to save the current page URL and redirect back after signup/login-->

<script>
  MemberStack.onReady.then(function(member) {
  if (!member.loggedIn) sessionStorage.setItem('redirect',window.location.href);
  })
</script>

and I put the below code at Login page https://roomindigo.webflow.io/account/login

<!--Place this on your page after signup/login - must be a hidden page-->

<script>
  var redirect = sessionStorage.getItem('redirect')
  sessionStorage.clear();
  if (redirect) window.location.replace(redirect)
</script>

Seems like every time I head over to login it will auto redirect me to Services page, and after login it won’t bring be back to Services page, may I know did I do it correctly any workaround on this? Thank you!

1 Like

Hey Steve, you’re suuuuper close.

  1. What page do you want to “Save” and send people to after signup?
  2. And what page do users land on (right now) after signing up and logging in? These are the pages you specified when setting up the membership.

You need to put the first snippet on #1 and the second snippet on #2.

Hi Duncan, thank you for the solution. But I tried that it works on login and registration but doesn’t seems to work on logout. But I found a pretty good video here https://www.youtube.com/watch?v=VsLZGk4W47w which works for all.