Hello everyone, I have this code in the site code tab, everything works except for the wixLocation. Because I seem to have done everything right
I hope someone will help me
Thank you
import wixLocation from 'wix-location';
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import {local} from 'wix-storage';
import {session} from 'wix-storage';
$w.onReady(function () {
$w("#LoginButtom").onClick( () => {
if (local.getItem("keyIsLoggedIn") === 'true') {
let path = wixLocation.path.toString();
if ((path === 'login') || (path === 'redirect-after-login')) {
$w("#LoginButtom").label = "Accedi";
$w("#SignUpButtom").label = "Registrati";
local.removeItem("keyUser");
local.removeItem("keyUserId");
local.setItem("keyIsLoggedIn", false);
wixUsers.logout();
wixLocation.to("/");
} else {
$w("#LoginButtom").label = "Accedi";
$w("#SignUpButtom").label = "Registrati";
local.removeItem("keyUser");
local.removeItem("keyUserId");
local.setItem("keyIsLoggedIn", false);
wixUsers.logout();
}
} else {
wixUsers.promptLogin({"mode": "login", "lang": "it"})
.then( (user) => {
$w("#LoginButtom").label = "Esci";
$w("#SignUpButtom").label = "Account";
local.setItem("keyUser", user);
local.setItem("keyUserId", user.id);
local.setItem("keyIsLoggedIn", user.loggedIn);
if (local.getItem("keyInfoAccount") === 'false') { //THIS WORK
wixLocation.to("/redirect-after-login"); //THIS NOT WORK
}
if (local.getItem("keyInfoAccount") === 'null') {
wixData.query("InfoUtenti")
.eq('member_UserId', userId)
.count()
.then( (risultato) => {
if (risultato === 0) {
local.setItem("keyInfoAccount", false);//THIS WORK
wixLocation.to("/redirect-after-login");//THIS NOT WORK
} else {
local.setItem("keyInfoAccount", true);
}
});
}
});
}
});
});