This article will show you how to redirect users away from pages they don't need anymore. Usually this is a signup or login page.
Add the following script to the Header or Footer of any page where you want to redirect logged-in members. The script will redirect more quickly if you place it in the header.
You'll want to replace "/"
with something else. Usually a dashboard page or profile page like "/dashboard"
.
<script>
const memberstack = window.$memberstackDom
memberstack.getCurrentMember().then((member) => {
if (member.data) {
window.location.replace("/");
}
})
</script>
Comments
5 comments
Very helpful!! Thank you ✨
Thank you !
Would there be a trick to put the "login-redirect" link inside of this script instead of a static link ?
Jean-Léonard Kayaleh Can you say more about your script? I'm not 100% sure I understand what you want to achieve. But I'm happy to help if I can!
Thank you very much for your answer Duncan from Memberstack.
What I meant is that the script you're proposing requires specifying the URL or slug where the user should land if they are logged in and they arrive on the login or signup page, for example.
In my case, I would need this URL to be that of my collection page, which uses a dynamic URL I've placed in the 'login-redirect' field of my user in Memberstack.
So, my question is whether it's possible to have something like this:
I know that this wouldn't work, but the idea is to be able to use the value entered in the 'login-redirect' field of my user.
Hey Duncan from Memberstack,
Hope you're doing great.
I succeeded to achieve what I requested you a few time ago... I share it here in case someone else would like to do the same.
Hope this helps 😊
Thank you again and all the best,
Jean
Please sign in to leave a comment.