# wixUsers.logout on protected page issue

**URL:** <https://forum.wixstudio.com/t/wixusers-logout-on-protected-page-issue/12441>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [December 11, 2017, 11:37pm UTC](https://forum.wixstudio.com/t/wixusers-logout-on-protected-page-issue/12441 "2017-12-11T23:37:02Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![mikemoynihan99](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mikemoynihan99/32/5930_2.png) [@mikemoynihan99](https://forum.wixstudio.com/u/mikemoynihan99)\
**Post date:** [January 12, 2019, 9:02pm UTC](https://forum.wixstudio.com/t/wixusers-logout-on-protected-page-issue/12441/21 "2019-01-12T21:02:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![stevendc](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stevendc/32/669_2.png) [@stevendc](https://forum.wixstudio.com/u/stevendc)\
**Post date:** [February 4, 2019, 6:52am UTC](https://forum.wixstudio.com/t/wixusers-logout-on-protected-page-issue/12441/22 "2019-02-04T06:52:50Z")

</div>

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.

```javascript
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

---

<div class="post-metadata">

**Author:** ![umut-cankurt](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/umut-cankurt/32/20370_2.png) [@umut-cankurt](https://forum.wixstudio.com/u/umut-cankurt)\
**Post date:** [March 23, 2019, 12:25pm UTC](https://forum.wixstudio.com/t/wixusers-logout-on-protected-page-issue/12441/23 "2019-03-23T12:25:41Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![admin-23](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/admin-23/32/708_2.png) [@admin-23](https://forum.wixstudio.com/u/admin-23)\
**Post date:** [March 26, 2019, 3:07pm UTC](https://forum.wixstudio.com/t/wixusers-logout-on-protected-page-issue/12441/24 "2019-03-26T15:07:29Z")

</div>

Umut,

Use [wixUsers.logout()](https://www.wix.com/code/reference/wix-users.html#logout) with [setTimeout()](https://www.w3schools.com/jsref/met_win_settimeout.asp)

---

<div class="post-metadata">

**Author:** ![mauro-vento-avyno](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mauro-vento-avyno/32/2432_2.png) [@mauro-vento-avyno](https://forum.wixstudio.com/u/mauro-vento-avyno)\
**Post date:** [April 28, 2019, 5:28pm UTC](https://forum.wixstudio.com/t/wixusers-logout-on-protected-page-issue/12441/25 "2019-04-28T17:28:45Z")

</div>

Has been Logout() Promise fixed, please ?

---

<div class="post-metadata">

**Author:** ![sanchezmarkanthony87](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/sanchezmarkanthony87/32/13149_2.png) [@sanchezmarkanthony87](https://forum.wixstudio.com/u/sanchezmarkanthony87)\
**Post date:** [July 4, 2019, 3:42am UTC](https://forum.wixstudio.com/t/wixusers-logout-on-protected-page-issue/12441/26 "2019-07-04T03:42:44Z")

</div>

**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();  
}

---

<div class="post-metadata">

**Author:** ![stevesoftwareservice](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stevesoftwareservice/32/10638_2.png) [@stevesoftwareservice](https://forum.wixstudio.com/u/stevesoftwareservice)\
**Post date:** [July 27, 2019, 6:39pm UTC](https://forum.wixstudio.com/t/wixusers-logout-on-protected-page-issue/12441/27 "2019-07-27T18:39:45Z")

</div>

Use Promise.all()

```javascript
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.

[Previous page](https://forum.wixstudio.com/t/wixusers-logout-on-protected-page-issue/12441.md?page=1)
