Hiding the homepage and redirecting to dashboard if logged in

Hi! Anyone know how to do this:

I have a homepage, which is the landing page that leads to signup. Once signed up (or if already logged in), is it possible to redirect people who landed on the homepage automatically to their dashboards?

Thanks for your input

Hey Vitaliyg :wave:

Thanks for the question! Yes, this is possible! Here is some code to do that.

<script>
MemberStack.onReady.then(function(member) {   
  if (member.loggedIn) {
     window.location.replace("/dashboard")
  }
})
</script>

This code would need to be added to your homepage! :smiley:

Awesome! Thanks Josh!

Currently my project’s homepage lives on project.com/url/demo

My dashboard URL is project.com/link/specific-user-id

Using the code above, it redirects to project.com/url/link/specific-user-id

How would I link those up?

Are you adding the member’s “specific-user-id” into Memberstack? If so you would add that in like this:

<script>
MemberStack.onReady.then(function(member) {   
  if (member.loggedIn) {
     var specificUserId = member["specific-user-id"];
     window.location.replace("/url/link/" + specificUserId);
  }
})
</script>

Yeah, we are. Correct me if I’m wrong, but the code above would require us to change the “specific-user-id” for every user?

With that code in place, the browser goes to /undefined and quickly redirects. (Probably isn’t finding the member ID)

Our member pages are automatically generated through webflow with the url being the member id taken from memberstack.

Ah ok! try this then! :smiley:

<script>
MemberStack.onReady.then(function(member) {   
  if (member.loggedIn) {
     var memberId = member.id;
     window.location.replace("/url/link/" + memberId);
  }
})
</script>
1 Like

That did it! Thank you always for your help, Josh! I really believe in you guys! Thanks for the help along the way.

2 Likes

This is a great example but I’ve got a little more complex need. How could you write this so that you can test for a specific member.membership (or multiple memberships) and then redirect users to different pages based on their current membership?