Page refresh when member logs in

Hi all,
Is there a clever somebody who could advise on an effective solution?
At the moment I am hiding a button from members not logged in. Only logged in members can see this button.

It works fine with Js code apart from when you are logged in the button remains hidden until page is refreshed. Is there a way to code a 1 time page refresh after member logs in?

i hope that makes sense?

Thank you from your friendly neighbor hood newbie

Hi!

Usually it should by default refresh the page on promptLogin as it is loaded for the first time after the user identifies. It is strange that elements aren’t loading after a login since it’s the same behavior as refreshing the page.

Meanwhile as a workaround I’d suggest you to use Wix-Location .to method and target the page itself at the end of the login event.

Please share a link to your site in the comments so we’ll be able to look into it.

Thanks and good luck!

Doron. :slight_smile:

Hi mimi,

I have the same problem. How do you fix the problem?

Regards

@bmrt82 Were you ever able to solve this issue? I am expanding some elements (Wix Video Library) on a page based on whether the user is logged in and, if so, their user roles. The code works fine except when a user is logged out and then logs in on the same page I have the expand code. I either have to refresh the page or navigate to another page and come back. I can’t redirect because the code is in the onReady event. It will keep rendering. So, I would like to know if there is a way to force it to refresh the page after the login. It does not perform a refresh as expected. By the way, the page works fine if the user is on the page with the expand code and logs out. In this scenario, the page refreshes and the updates to the page are visible.

To save rendering time, I don’t need to refresh the whole page. I could re-render a portion of it.

@elania

create a lightBox for login, you can activate the login lightbox with an onClick event on your webpage, then code something like this on the lightbox page:

import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
import {local} from ‘wix-storage’;
import wixWindow from ‘wix-window’;

$w.onReady( function () {

$w('#LoginButton').onClick( **function**  () { 

if (wixUsers.currentUser.loggedIn) {

// logout the user

        wixUsers.logout() 

            .then(() => { 

//refresh the current webpage

                wixLocation.to(wixLocation.url) 

                    .then(() => { 

                        wixWindow.lightbox.close(); 

                    }) 
            }) 

    }  **else**  { 

//login the user

let email = $w(‘#LoginEmailInput’).value;

let password = $w(‘#LoginPasswordInput’).value;

        wixUsers.login(email, password) 

            .then(() => { 

//refresh the current webpage

                wixLocation.to(wixLocation.url) 

                    .then(() => { 

                        wixWindow.lightbox.close(); 

                    }) 
            }) 
    } 
}) 

})

@mikemoynihan99 It looks like the onLogin() event handler (part of the wix-users API) was exactly what I was looking for. I put it in my onReady() event and added the wixLocation.to(wixLocation.url) to force a refresh of the current web page. I debated putting the code at the site level, but opted for the page level, since I really don’t need to force a refresh on every page each time a user logins. The elements which are expanded or collapsed based on the user login (and, if logged in, their roles) works now when the user logs in while on that particular page.

@elaina hi Elaina, could you please share the code you used with your onReady() event?

Thank you!

@melcollmusic

This is my custom login lightbox code, use it or use what Mike has already posted above in his reply.

If you are going down the custom login/signup route, then you need to enable custom site registration in your settings too in the Wix Editor.
https://support.wix.com/en/article/wix-code-enabling-custom-site-registration

import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';

$w.onReady(function () {
 $w("#forgotPassword").onClick( (event) => {
    //wixWindow.lightbox.close()
   wixUsers.promptForgotPassword()
   .then( ( ) => {
   //
   } )
    .catch( (err) => {
    let errorMsg = err;  //"The user closed the forgot password dialog"
    });
 });
});

export function loginButton_onclick(event) {

 let email = $w("#email").value;
 let password = $w("#password").value;

 wixUsers.login(email, password)
   .then( () => {
     console.log("User is logged in");
     wixWindow.lightbox.close();
     wixLocation.to(wixLocation.url);  //This reloads the same page and allows code to show hidden member parts.
   } )
    .catch( (err) => {
     console.log(err);
     $w("#errorMessage").expand();  // You can delete this line if you are not going to add an error message.  Use a regular text element set to 'collapse on load' from the Properties Panel.
   } ); 
}

@melcollmusic Do you still need an example of my code?

Thanks guys for your answers, I did find a solution however I moved to Wordpress as Wix just was not working for what I needed for memberships and for downloading documents. There were too many fixes and coding snippets for simple actions :frowning:

The database system was clunky as I had a 100 + downloadables. Wordpress has been my saving grace with this project and can be customised front end through plug ins. I do use wix for my other sites but found it did not Work for anything more than a simple e-commerce site sadly. That’s my experience anyway !

1 Like

import wixLocation from ‘wix-location’;

$w.onReady( function () {

//add an onclick here or some other event to trigger the below page refresh

wixLocation.to.to(wixLocation.url);

})

3 Likes

Yep. That is it. I used onLogin() as the event which triggered my page refresh

1 Like

How can we achieve the same refresh, but after redirecting to a new page?

I want my users to land to a welcome page after sign-up (not login) which should show collection elements stored during the registration function I wrote custom. These elements appear only if I manually refreshing the page.

I have a lightbox with something like

$w(‘#SubmitButton’).onClick(() => {

wixUsers.register($w(‘#email’).value, $w(‘#password’).value, {

// storing additional data in a custom database collection upon signup

}).then(() => {

                wixWindow.lightbox.close(); 
                wixLocation.to("/signup-confirmation"); 

            }); 

}

The additional data I stored in the register function should be retrieved automatically and shown in the signup-confirmation page upon load, but they actually appear only after I refresh manually the page.

Any idea on how I can achieve this? This is driving me mad since 3 days already, any help is super appreciated :slight_smile:

Thanks!

import wixUsers from 'wix-users';
import wixWindow from 'wix-window';
import wixLocation from 'wix-location';

$w.onReady(function () {
    
    $w("#registerButton").onClick( (event) => {
        
   let email = $w("#email").value;
   let password = $w("#password").value;
   let first = $w("#firstName").value;
   let last = $w("#lastName").value;

   wixUsers.register(email, password, {
       contactInfo: {
        "firstName": $w('#firstName').value,
        "lastName": $w('#lastName').value,
       }
      } )
      .then( (result) => {
        let resultStatus = result.status;
  wixWindow.lightbox.close();
  wixLocation.to("/sign-in-status");  //Change the URL ending to whatever page you want to send the user to after they log in.
      } );     
    } );
    
});

Now that all depends on what you have set up your new members to do after registration, either manually approve or automatically approve.

My signup lightbox code below works fine perfectly and closes after registering details before moving user on to my signup status page, then both names will be saved in contacts and once site member is manually approved the member details will be added to ‘members’ database.
https://support.wix.com/en/article/approving-a-site-member
Who can be a member? Choose who can be a member of your site:
Everyone: When a new member signs up, they are approved automatically. You do not need to do anything.
People I approve: When a new member signs up, you receive a notification, both by email and in your site’s dashboard, asking if you want to approve or reject them. Only those who you approve become site members.

Hence why you can’t get the members details from the custom dataset that you have added, like in this tutorial here.
https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area

If you use Wix CRM, then you will be able to get certain parts of the new site members info through the contacts in your Wix dashboard before they are saved into your additional members dataset and then you can use Wix Users.