Redirect to a specific page after Member Log In

When a member logs in, I want to direct them to a specific page.
The code only works from the public pages (the default domain URL which I have masked below).
Working in
e.g. Wix Studio Editor, Wix Editor, Dev Mode, CMS, etc.

Site link
If this is happening on a site, include a live or test site link

What I’m trying to do
From a prior post, I posted some code into the site and it works GREAT all but one important part.

Here is the code; the masked section is the Domain Name followed by the desired default member log in page (Let’s call it page 1).

If the member is on a public page before logging on, it works great . But I have ten pages under the member log in menu. If the user logs out on say page 7, when they log back in it remembers where they were and takes them to page 7 - instead of the desired Page 1 of the Member log in menu. How do I modify this code to happen on all volunteer pages (2-10)? Thank you so much for your help. I am not a coder…. Sjj

What I’ve tried so far
Let us know what you’ve already tested, changed, or searched

Extra context
Anything else that might help - edge cases, screenshots, etc.

try this - replace “/page-1” with the url of the page you want.

For example, if the full page URL is:

https://www.yourdomain.com/volunteer-home

then use:

wixLocation.to("/volunteer-home");

import { authentication } from 'wix-members-frontend';
import wixLocation from 'wix-location-frontend';

$w.onReady(function () {
    authentication.onLogin(() => {
        wixLocation.to("/page-1");
    });
});


So I made the change - and it works the same and I am now getting a lot of run errors -
See this:

I have determined that if the user X’s out of the Popup login screen - everything works fine. But if they leave the login screen in their browser - it remembers their last page.

Any further ideas?

What you’re seeing is expected Wix behavior. The log lines shown are just informational, not actual run errors. The real issue is that Wix’s built-in member login flow remembers the page the member logged in from, and Wix currently does not support forcing all logins to go to one specific page.

Putting authentication.onLogin() in site code can help in some cases, but it won’t reliably override Wix’s native return-to-last-page behavior for protected member pages.

The more reliable workaround is to use a custom login button with await authentication.promptLogin() and then redirect with wixLocation.to("/volunteer-home-page") after login succeeds. If the visitor closes the popup, nothing happens.

If they log in through Wix’s default protected-page flow, Wix may still return them to the page they started from.

1 Like

thank you . I won’t be able to address this for a day or two. I really appreciate your help! And response.

I think I will just leave it with the partial workaround. It is better than it was. The other solution you propose sounds better, but I don’t have the experience to do that. Thanks again! So much!