Return to Page after Sign Up or Login

Article author
Duncan from Memberstack

This article will show you how to return members to the page they were viewing before being asked to sign up or login. This is especially handy if you have a content or functionality that is partially gated (like a blog or comment sections).

data-ms-redirect="current-url"

Use the attribute data-ms-redirect="current-url" to save the current URL. The next time that visitor goes to sign up or login they will be returned to the page. 

return to page (1).jpg

You can place the attribute anywhere, but we recommend placing it on your signup and login links. 

Considerations

Keywords:

Stay on page, stay-on page, override redirect, after login, after signup, save page, save url, current url, 

Was this article helpful?

Comments

14 comments

  • Comment author
    Mark Burlinson

    This did not work for us. 

    0
  • Comment author
    Duncan from Memberstack

    Mark Burlinson Do you have a redirect hard-coded into your signup/login form by chance? 

    I just did some testing and this feature is working as expected for me. It you can share a video or read-only link that would be super helpful to debug 🙏

    0
  • Comment author
    Joseph Carroll
    • Edited

    Duncan Hamra Does this data-ms-redirect attribute work for URL's where there's gated content?

    For context:

    - User clicks on link from email to go specific page

    - Page happens to be gated content (user is not logged in)

    - MS kicks user to log-in page (normal behavior)

    - On log in event --> page redirects from plan level redirects back to original URL they were 'kicked out of'.

    Thanks a mill!

    Joe

    ++ update ++


    I did add this attribute to the main nav of my web app. (This is a common element across my Member area.)
    This did not work. I understand it should likely be a form element.

    I did try it on my login button on my login *page* (not modal), but obviously that just grabbed the current URL (which was "log-in") which directed me back to itself.

    I have 8+ pages on my web app, sometimes I need to send users straight a specific page (once they log in). I might just hard code this as a cookie and do some logic here if this isn't native to MS. Thanks!

    0
  • Comment author
    Duncan from Memberstack

    There's no way for it to remember the first page if that page is gated. This attribute only "remembers" the current URL if it is clicked by the member. 

    Thank you for the update! I just tested the attribute on my own site, and it all appears to be working correctly. If the member clicks a link or section with the attribute they will be returned to the page on login. 

    1
  • Comment author
    Joseph Carroll

    Thanks Duncan from Memberstack! I appreciate the response.

    1
  • Comment author
    Drew Birnie

    Could I use this in the following situation:

    1. A user is taken to a pricing page where they select a recurring payment plan

    2. Upon submitting the pricing form, they're are taken to a signup form where they can either create an account or log in

    3. If the user already has an account (for a different product), they can log in and be taken straight to the Stripe payment form. 

     

    I'm scratching my head on this one as it seems like it should be pretty straightforward, but this solution seems like it would just keep them on the signup/login form. 

    0
  • Comment author
    Duncan from Memberstack

    Drew Birnie Thanks for asking!

    1. Yes, no problem. They can select a pricing plan by clicking on a button with a price attributes. 
    2. Also fine. If you add a sign up link (i.e. /signup) to your pricing button it will redirect them to your sign up page. From here they can signup or create an account. After signup they will be taken straight to checkout. 
    3. If the users already has an account and is logged in, they will be taken directly to the checkout from the pricing page. 

    Does that make more sense? No worries if not, just let me know and I'll record a video. 

    0
  • Comment author
    Drew Birnie

    Duncan from Memberstack


    What if the user has an account and is NOT logged in? I'm having issues with that scenario. This is what happens in that case right now:


    1. They select a pricing plan on a pricing page and click on "checkout"

    2. From there, they are directed to the signup form

    3. They click on "Already have an account? Log in." and are taken to the login form where they can successfully log in

    4. Once they do, they're taken to their member dashboard <<< This is where the problem is. I need them to be taken to the Stripe payment form for whichever recurring plan they selected. 

    0
  • Comment author
    Duncan from Memberstack

    Ahh right! Thank you for clarifying. 

    Have you seen this MemberScript yet? If you add it to your site I believe it will fix your issue. https://docs.memberstack.com/hc/en-us/community/posts/18410652090139-How-to-Launch-Checkout-after-Login

    0
  • Comment author
    Ben Walsh

    Hey there, It's not 100% clear where I should add this code.
    I'm using the Memberstack modals.

    Can this be anywhere on the page?
    Or does it need to be on the button that triggers the modal?

    0
  • Comment author
    Duncan from Memberstack

    I recommend adding it to the same button that triggers the modal. 

    1
  • Comment author
    Ben Walsh

    That worked perfectly - thanks Duncan from Memberstack

    0
  • Comment author
    Braden Mosley

    Hey Duncan! Love Memberstack!

    Is there any way to only redirect back to this page on login?

    I’d like to still use Onboarding UI for sign up.

    Thanks!

    1
  • Comment author
    Memberstack Team

    Hey Braden, thanks for the kind words 🙏

    I see why you'd want that, sadly this attribute does not allow for it. That said, I think it could be possible with custom code. First idea that comes to mind. It would essentially turn any page into your onboarding page until the onboarding from is complete.

    1. Add your onboarding form in a symbol to each page. Set the UI to display none. 
    2. Add a custom field called "Returning Member" in Memberstack.
    3. Then add a hidden input for "Returning Member" to your onboarding form with a default value equal to true. This way when the form is submitted the custom field gets set to True. (By default it's blank)
    4. Next, add a script to the on boarding UI which checks to see if Returning Member is blank or has a value. If it is blank, display the onboarding UI. If it has a value, then do nothing. 

    If you give this info to Rey (the AI) it can help you create the custom code. 

    0

Please sign in to leave a comment.