Hi,
I’m using the wix-users.logout() function on one of my pages. Is it possible to logout users if they refresh the page? If yes, how? Any suggestions?
Hello Vipul,
There is no direct method but there is a work around.
- Get the referrer address (previous address)- here
- Check to see if the referrer address is the same as the current one - here
- If it is log the user out, else do nothing - here
Let me know if this helps,
Majd
Hello Majd,
Thanks a lot for the reply. I tried what you suggested but it did not work. Here’s the piece of code that I used:
import wixWindow from 'wix-window';
let referrer = wixWindow.referrer; // gets previous window address
let url = wixLocation.url; // gets current window address
$w.onReady(function () {
if (referrer === url) {
wixUsers.logout();
}
}
What I believe is that referrer will only work if the user clicks a link and visits the page but I don’t want that. Anything else that could work?