Problem with Login Button and wixUsers.logout( )

It appears that when the user logs out using the Wix Members login button, wixUsers.logout( ) is not called.

I put a breakpoint in my wixUsers.logout( ) code, and it was not reached.
Can anyone confirm this?

Make sure you have the correct names for the login button. Such as the ID in itā€™s place or it wonā€™t work properly. Look at this : YouTube

I see that I was actually mistaken.

Originally I thought wixUsers.logout( ) logged the user out (which it does!)
In the course of looking at documentation, I got the idea that if was a kind of handler, which would be called when a user has finished logging out. (Like a sister-function to onLogin( )).

Which leads me to the question ā€¦ why is there no wixUsers.onLogout( ) function, which is called when the user finished logging out?

I am trying to change the appearance of some things like a ā€œProfileā€ button and a user icon, when someone logs out, so that those things are no longer seen. You canā€™t do anything like that without an onLogout( ) as far as I am aware.

I had to resort to adding a setInterval( ) which checks every fraction of a second, if the user is still logged in, and if they are not, changes the graphical elements. This is woefully inefficient.

1 Like

Hi Mike,

logout() return a function that is resolved when the user is logged out,
You can use:

wixUsers.logout()
  .then( ( ) => {
    console.log("User logged out");
  } )
  .catch( (err) => {
    let errorMsg = err; // "No member is logged in"
  } );

Hi Liran,
Does having the line wixUsers.logout() in your code cause the user to be looged out immediately, or is does it only allow you to handle a log out event?

Hey Mike,
It does both.
User is logged out and a promise is resolved (with no arguments):

wixUsers.logout()
  .then( ( ) => {
    console.log("User logged out");
  } )
  .catch( (err) => {
    let errorMsg = err; // "No member is logged in"
  } );

Liran.

I can assure that the event handler ā€˜authentication.onLogout()ā€™ is running after click logout from the login bar. For website lang ES version runs but do not apply the change and the wixUser.currentUser.loggedIn still true and for that case trying to logout in there wixUsers.logout() runs in infinite cycle.