Skip to main content

How to redirect members to their login page after authentication?

is where anyway to redirect a member back to the page they logged in from?

19 comments

  • Jayess
    Jayess

    Hi Connor 👋
    Great question! Hm, try this out and see if this fits your use case 😀

    0
  • Chuck Lapointe
    Chuck Lapointe

    That’s useful Jayess

    Does this also work for example if we ask someone to login from an article page? User flow would look like this:

    Article page > Login page > redirect back to the article page after success?

    0
  • Julian Galluzzo
    Julian Galluzzo

    Chuck Lapointe yup! Whatever page they logged in from will work.

    Heres a demo we just released which should help along with the article shared by JS
    https://webflow.com/made-in-webflow/website/dont-redirect-on-login-memberstack

    0
  • Chuck Lapointe
    Chuck Lapointe

    Hey Julian Galluzzo So that’s the problem, is they would be redirected to a login page that is a step after. I have a custom JS script that inserts a cookie and then redirects back, but thought there might be a cleaner way 😅

    0
  • Julian Galluzzo
    Julian Galluzzo

    this way would probably work better than with a cookie since cookies usually take more time to get recognized after the page load (from what ive seen) - the one in this example is pretty much instant, you dont notice you're even being redirected to the "in between" page unlezs you stare into the url bar and catch the few ms of loading time

    0
  • Chuck Lapointe
    Chuck Lapointe

    sounds good! Thanks

    0
  • Julian Galluzzo
    Julian Galluzzo

    No problem!

    0
  • Connor Finlayson
    Connor Finlayson OP

    so, in this example would always be redirected back to the page that they were on. I only needs to work on a few select pages, but on every page

    0
  • Julian Galluzzo
    Julian Galluzzo

    Connor Finlayson Idea:
    https://www.loom.com/share/b2e5c66707624bbbb981f53d741107b5

    0
  • Connor Finlayson
    Connor Finlayson OP

    hey this actually works nicely. I just need to find a way to clear the location once they have been redirected back to that page

    0
  • Julian Galluzzo
    Julian Galluzzo

    Sweet! I have to ask, what's the need to clear the location? I would think it would just be a harmless URL saved in the local storage.

    Regardless, I have an idea - a script somewhere in the body which checks if _ms-mem is saved in their local storage (only true if user is currently logged in)

    If it is present, clear location from local storage

    0
  • Connor Finlayson
    Connor Finlayson OP

    if someone logs in on the profile page I want them redirected back to the profile page, if they login from the homepage, I want to redirect them to the redirect page set for their plan

    in short if they login at /profiles/ redirect to the page they were on

    If any other page, redirect to the redirect link as per the memberstack plan

    0
  • Marc Hudson
    Marc Hudson

    Maybe a question for Jayess. I’m looking to achieve this login/register redirect too and I see in the Docs under “data-ms-form=“login” that it says "Adding a redirect to the form element will override redirects saved in Memberstack." Sounds perfect, but there isn’t an example of this “redirect” method in the HTML snippet. Is this a feature of Memberstack or something that hasn’t made it to Prod yet?

    I’ll use the localStorage method in the meantime.

    0
  • Julian Galluzzo
    Julian Galluzzo

    Marc Hudson if you're using Webflow, you should just be able to add the form redirect URL in the settings - that being said, that would only work if you have a bunch of different signup/login pages - this method allows you to use one page and have it redirect accordingly

    0
  • Marc Hudson
    Marc Hudson

    Hey Julian Galluzzo. Ah, I forgot about that. I tested that option but unfortunately it seems Memberstack’s Redirect on login (User specific) value is trumping the forms redirect value. I was hoping individual forms would have the final say but it doesn’t seem that’s the case. I’ll use the localStorage method 🙂

    I should say that I have 2 different login forms. 1 generic login that redirects each user to their Dashboard and another that appears on specific pages that I’d like to redirect to. That’s why the form’s redirect value having the final say would be handy in this case

    0
  • Nicolas Erlichman
    Nicolas Erlichman

    Hey!

    We have some pages that when a user that is not logged in tries to access, they get redirected to the login page.

    I found this article, but it stated that it was for “partially gated” gated pages. In my case the full page is inaccesible and user never gets to load the page, they get immediately redirected to the login page. Will this still work?

    0
  • Chukwudi
    Chukwudi

    That would still work for you. Alternatively, you can use the code-based approach in this article: Keep Members on the Same Page After Signup or Login.

    0
  • Nicolas Erlichman
    Nicolas Erlichman

    That’s great to know! I will try it out, thank you!

    Using gated content functionality with the code version doesn’t work, as it will store the path of the login page ([domain]/login) instead of the path of the page were it came from (test-redirect-page)

    0
  • Chukwudi
    Chukwudi

    If you made the code below site-wide, I recommend removing and placing it individually on the gated pages or directories instead.

    <script>
    // sets the url of the page you're on for redirecting back to it
    localStorage.setItem('locat', location.href);
    </script>
    0

Please sign in to leave a comment.

Sitemap