# LOGOUT

**URL:** <https://forum.wixstudio.com/t/logout/14487>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [January 5, 2019, 8:15pm UTC](https://forum.wixstudio.com/t/logout/14487 "2019-01-05T20:15:20Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![bobmitchy](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bobmitchy](https://forum.wixstudio.com/u/bobmitchy)\
**Post date:** [January 5, 2019, 8:15pm UTC](https://forum.wixstudio.com/t/logout/14487/1 "2019-01-05T20:15:20Z")

</div>

I would like to go back to my home page upon logout…  
it leaves me on current page…  
is this possible?  
regards bob

---

<div class="post-metadata">

**Author:** ![carlosgalvarez](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/carlosgalvarez/32/2194_2.png) [@carlosgalvarez](https://forum.wixstudio.com/u/carlosgalvarez)\
**Post date:** [January 5, 2019, 8:55pm UTC](https://forum.wixstudio.com/t/logout/14487/2 "2019-01-05T20:55:47Z")

</div>

You will need to use wixLocation.to to route to the homepage onLogout. If you do a quick search you’’ find some examples on this

---

<div class="post-metadata">

**Author:** ![bobmitchy](https://avatars.discourse-cdn.com/v4/letter/b/a9adbd/32.png) [@bobmitchy](https://forum.wixstudio.com/u/bobmitchy)\
**Post date:** [January 6, 2019, 9:47pm UTC](https://forum.wixstudio.com/t/logout/14487/3 "2019-01-06T21:47:48Z")

</div>

Do i need to write my own login/logout or can i modify the default one

---

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [January 12, 2019, 5:48pm UTC](https://forum.wixstudio.com/t/logout/14487/4 "2019-01-12T17:48:44Z")

</div>

@bobmitchy Hi Bob, did you have any luck with this?

---

<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/logout/14487/5 "2019-07-04T03:42:00Z")

</div>

Need help plz…

Why i can’t logout my members login but still the page will move to the front page?

**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:** ![doron-alkalay](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doron-alkalay/32/2887_2.png) [@doron-alkalay](https://forum.wixstudio.com/u/doron-alkalay)\
**Post date:** [July 4, 2019, 12:41pm UTC](https://forum.wixstudio.com/t/logout/14487/6 "2019-07-04T12:41:08Z")

</div>

![](https://us1.discourse-cdn.com/wix/original/3X/7/e/7e6abcc076597ecf1a127bea271512f54f0bb713.gif)  
@sanchezmarkanthony87

The code as you posted will first relocate the user and then ignore the rest since it has moved to another page.

What you should do is to check in your site onReady code if the  
wixUsers. [currentUser](https://www.wix.com/corvid/reference/wix-users.html#currentUser) is [logged in](https://www.wix.com/corvid/reference/wix-users.User.html#loggedIn) , if it is not - simply redirect him to the relevant page (the home page for instance).

Whenever the user is being logged out, the page is rendered again - refreshed.

Let me know if it works for you.

Doron.

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [July 4, 2019, 1:23pm UTC](https://forum.wixstudio.com/t/logout/14487/7 "2019-07-04T13:23:37Z")

</div>

Looks like you were following @code-queen tutorial as shown here.  
[https://support.totallycodable.com/en/article/create-log-out-button-with-redirect-to-another-page-using-wix-code](https://support.totallycodable.com/en/article/create-log-out-button-with-redirect-to-another-page-using-wix-code)

Code From Tutorial:

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

As it was code from Nayeli herself, you could have asked her why it was not working first and then came here if she didn’t get back to you afterwards.

However, if you can not get this code to work for yourself, then try Steve’s option as well as shown here.  
[https://www.wix.com/corvid/forum/community-discussion/this-is-how-to-logout-and-go-to-the-page-of-your-choice](https://www.wix.com/corvid/forum/community-discussion/this-is-how-to-logout-and-go-to-the-page-of-your-choice)

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [July 4, 2019, 1:39pm UTC](https://forum.wixstudio.com/t/logout/14487/8 "2019-07-04T13:39:54Z")

</div>

Hola Marco Antonio …

Check out this Wix’s original tutorial on creating a member page. In their code they:

(1) Check if logged in  
(2) Prompt log in, if not  
(3) Then redirect to another page

You can possibly use this code as a guide to do the opposite.

Link: [https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area#code](https://support.wix.com/en/article/corvid-tutorial-building-your-own-members-area#code)

The other code you posted is just a code snippet, also, to use as a starting point. It all depends on where and how you use it. Logic of the page and flow also has a lot to do with the logic of code to complete it.

---

<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 5, 2019, 1:15am UTC](https://forum.wixstudio.com/t/logout/14487/9 "2019-07-05T01:15:32Z")

</div>

sorry maam/sir… it already work… i just forgot to published it… my mistake

---

<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 5, 2019, 1:15am UTC](https://forum.wixstudio.com/t/logout/14487/10 "2019-07-05T01:15:47Z")

</div>

sorry maam/sir… it already work… i just forgot to published it… my mistake

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [July 5, 2019, 1:53am UTC](https://forum.wixstudio.com/t/logout/14487/11 "2019-07-05T01:53:40Z")

</div>

Ahhhh yes …

The publish button helps sometimes 😘

---

<div class="post-metadata">

**Author:** ![jeff17](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jeff17/32/4963_2.png) [@jeff17](https://forum.wixstudio.com/u/jeff17)\
**Post date:** [July 11, 2020, 8:56pm UTC](https://forum.wixstudio.com/t/logout/14487/12 "2020-07-11T20:56:15Z")

</div>

You have to put the logout command after the page command.

```javascript
wixLocation.to(`/`) 
wixUsers.logout();

```

This will trigger the main page or home page to, then it will trigger logout RIGHT after.
