I saw multiple posts on this topic, it seems to come up quite often but none seem to have really resolved it in a straight-forward manner, and/or I don’t really understand them. HELP!
I am in the editor, using just the default Wix login/logout function. when a member logs out of a members-only page, I want them to be redirected back to home page. Do I put some code into the box “Site Code” at the bottom of the editor? Any help would be appreciated, thanks a lot!
well first thing is —> yes the CODE belongs to the SITE-SECTION, because you want this CODE to work on all of your pages.
Second: Perhaps this can help you…
import wixUsers from 'wix-users';
$w.onReady(function () {
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
if(!isLoggedIn){console.log("User not logged-in.");}
else {console.log("User logged-in");}
})
You have just to set the missing redirection.command and import the related API to this command. ----> location
Thank you so much! This is super helpful. sorry I am very new to this, could you elaborate on how to " set the missing redirection.command and import the related API"?
Thank you! I ran into a problem because if a user is not logged in, the code always takes the user back to the homepage no matter what. How do i modify the if statement to say “if user just decided to log out”, instead of “if user status is not logged in”?