Return to previous page on login / register

When people register or login, you can specify the page they then go to, but is there a way to let them return to where they were previously? ie, the page on which they clicked “login” or “register”

1 Like

Here is the workaround:

Create a page where “you’re signed up, please wait for 3 seconds, you will redirected to your previous page” or “you’re loggedin, please wait for 3 seconds, you will be redirected to your previous page” is written (or whatever you want, it must clearly explain that nothing has to be done by the user. I suggest to remove any header or footer too)

In this newly created page insert this code in the footer of the code settings of the page:

<script>
  setTimeout(function() {
    window.history.go(-2);
  }, 4000);
</script>

The script makes the user going back 2 pages before the “you’re signed up / logged in” page
Fell free to reduce the 4000 (milliseconds) to 2000 or even 1500

Any help for the setup, just reply and I will see what I can do

@Suzie This is a highly requested feature to be native! :grimacing:

1 Like

Thank you. We currently have login and register pages set to open in a new tab so users don’t lose their place, but they have come to expect the “return me to where I was” UX.

1 Like

Great, Thanks matthieu !

1 Like

Yes @Suzie it is pretty insane that this is not out-of-the-box… When Softr recently did a poll on which new “features” to build, I would argue next to that to increase programming output of your dev-team and work through a gazillion of these Quality of Life improvements as well.

edit: Thanks Matthieu

@artur Can we simply catch the success event on the login form block and use something like window.location.href = redirectUrl;; grabbing redirectUrl from a URL search parameter in a link? This would at least allow us to use links to specific pages and redirect the users to those pages after logging in.

I haven’t tested this out yet, but maybe something like this might work.

Assuming a link https://yourwebsite.com/login?redirect=/specific-page

Grab the URLSearhParams:

const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const redirectUrl = urlParams.get('redirect');

On login form success, redirect user:

// assuming `redirectUrl` is the URL parameter with the intended page URL
if (redirectUrl) {
  window.location.href = redirectUrl;
} else {
  // if no redirect URL parameter is found, redirect to the default page
  window.location.href = '/home';
}

Why not using our login page redirects ? is it not enough for your use case ?

For my use case, no. Or at least I haven’t figured out how to make it work.

I have emails generated in Airtable that contain links to specific list detail pages. If the user is not logged in when they click on the link, they are redirected to the page set in the login redirect for their group. Same for anyone following the link that isn’t already a user. When they sign up, they are not redirected to the linked page.

@rhinonix a history.back(-1) after sign up would do the trick?
@artur signup forms are under react now?

@rhinonix @matthieu_chateau next week signups will also be released and then we can attach events on success and do custom redirects too