wixUsers.logout on protected page issue

you can create events for objects such as buttons,text, shapes, etc.

If you put any one of these on your page you can create a onClick event to logout the user and redirect them to what ever page when they click on the button,text, shape, etc.

Unfortunately Ido’s and Liran’s suggestion are incorrect. wixUsers.logout DOES NOT return a Promise so you cannot do anything after you call logout() because you are logged out. This would however be a great feature request ;-).

If you add a test for if the user is logged in to the onReady function. Then when you cancel the login dialogue the page will redirect to where you choose. For example if the user is logged off then you can redirect to home page.

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

$w.onReady( () => {
    if (!wixUsers.currentUser.isLoggedIn) {
        wixLocation.to('/');
    }
});

This may not be perfect but it will do the job.

Cheers

@Ido (Wix)
Hi;

Is there a code that I can add to close the session automatically when the user has logged in after a certain timeout? sample

Umut,

Use wixUsers.logout() with setTimeout()

Has been Logout() Promise fixed, please ?

import wixUsers from ‘wix-users’;
import wixLocation from ‘wix-location’;
$w.onReady( function () {
//This section stays blank if you don’t need any actions to occur when the page loads and is ready.
});
export function beginCourse_click() {
wixLocation.to(“/”)
wixUsers.logout();
}

Use Promise.all()

function logoutButton_click() {
    return Promise.all([
        wixLocation.to("/"),
        wixUsers.logout()
    ]);
}

This will execute both functions simultaneously until they both complete. Most other solutions do not.