Refresh page when members log in

Hello eveybody!

I am designing a website with a restricted area for logged-in members.
On the welcome page, I would like members to know if they are loggeg-in or not with a very simple message:

for visitors unlogged, message #1:

"Pour accéder à l’espace réservé aux adhérents, ouvert aux seuls personnels des adhérents, une connexion est requise. Ceci nécessite une inscription et sa validation. Pour vous inscrire, veuillez cliquer dans le bouton < Connexion à l’Espace ‘‘Adhérents’’ > "

for visitors logged-in, message #2:

“Vous êtes bien connecté, et vous pouvez accéder à l’espace réservé aux adhérents.”

I coded the following:

import wixUsers from ‘wix-users’ ;

$w . onReady ( function () {
let user = wixUsers . currentUser ;
let isSignedIn = user . loggedIn ;

if ( isSignedIn  ==  **false** ) 
{ 
    $w ( '#text72' ). text  =  "Pour accéder à l'espace réservé aux adhérents, ouvert aux seuls personnels des adhérents, une connexion est requise. Ceci nécessite une inscription et sa validation. Pour vous inscrire, veuillez cliquer dans le bouton < Connexion à l'Espace ''Adhérents'' >." 
} 

else
{
$w ( ‘#text72’ ). text = “Vous êtes bien connecté, et vous pouvez accéder à l’espace réservé aux adhérents.” ;

}

});

It works fine for people logging out… the page refreshs as it should, and the right message, message #1, appears.

On the other hand, it doesn’t work for people logging in… once they enter their address and password, the page doesn’t refresh as it should. The message #1 remains in place, and the right message, message #2, appears only after a manual refresh.
I would like the refresh to be automatic, and the logged-in member to remain on the same welcome page.

I saw some posts on similar problems, and read and tried the proposed solutions. None of them worked for me.

Could somebody help me to solve the issue?

Thank you for your help!

Kind regards,

First of all…

…you are using an old API.

Wix-Users-Api is an old and depricated api.

Instead of Wix-Users, take a look at…
https://www.wix.com/velo/reference/wix-members
…and this one…
https://www.wix.com/velo/reference/wix-members/authentication/onlogin

dear Velo-Ninja

I apologize as I am starting to learn the powerful Velo tool. I copy code pieces on the web, and there are a lot of old stuff.

Following your comments, I write the following:

"
import { authentication } from ‘wix-members’ ;

const isLoggedIn = authentication . loggedIn ();

if ( isLoggedIn ) {

{
$w ( ‘#text72’ ). text = “Vous êtes bien connecté, et vous pouvez accéder à l’espace réservé aux adhérents.” ;

};
} else {
$w ( ‘#text72’ ). text = “Pour accéder à l’espace réservé aux adhérents, ouvert aux seuls personnels des adhérents, une connexion est requise. Ceci nécessite une inscription et sa validation. Pour vous inscrire, veuillez cliquer dans le bouton < Connexion à l’Espace ‘‘Adhérents’’ >.”
}

// …

authentication . onLogin ( async ( member ) => {
$w ( ‘#text72’ ). text = “Vous êtes bien connecté, et vous pouvez accéder à l’espace réservé aux adhérents.” ;
});

"

and it works…

Nevertheless you may suggest better practises in coding, and I am willing to learn.

Kind regards,

Philippe