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 is logged in, 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.
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.
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.
});
exportfunctionbeginCourse_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.
Wishlist Page is the new official platform for requesting new features. You can vote, comment, and track the status of the requested features (requests from this page will be migrated to the new Wishlist soon).
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
Do i need to write my own login/logout or can i modify the default one
@bobmitchy Hi Bob, did you have any luck with this?
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();
}
@Mark Anthony Torrequemada Sanchez
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 is logged in, 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.
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
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.
sorry maam/sir.. it already work.. i just forgot to published it.. my mistake
Looks like you were following @Code Queen Nayeli tutorial as shown here.
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
sorry maam/sir.. it already work.. i just forgot to published it.. my mistake
Ahhhh yes ....
The publish button helps sometimes 😘
You have to put the logout command after the page command.
wixLocation.to(`/`) wixUsers.logout();
This will trigger the main page or home page to, then it will trigger logout RIGHT after.