Hello I’ve created a login(signup) button, signup details have been stored in database if someone does fill from “desktop”.
But If do fill from Mobile it shows “account created” but I don’t get data in the database and the Login btn label still the same “login” on the mobile device.
Website:www.useus24.org/account
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import { fetch } from 'wix-fetch';
// let ipAddress;
$w.onReady(function () {
const selectedTab = "#8015E8"; // For selected tab
const otherTab = "#BA83F0"; // For other tabs
setTimeout(loginCheck,500);
// getUserIP();
$w('#homeButton').onClick(() => {
$w('#AcStatebox').changeState("homeState");
});
$w('#profileButton').onClick(() => {
$w('#AcStatebox').changeState("profileState");
});
$w('#walletButton').onClick(() => {
$w('#AcStatebox').changeState("walletState");
});
$w("#AcStatebox").onChange((event) => {
const buttonNames = ["home", "profile", "wallet"];
buttonNames.forEach(buttonName => {
let button = $w("#" + buttonName + "Button"); // e.g. $w("#keyboardsButton")
let state = buttonName + "State"; // e.g. keyboardsState
if (event.target.currentState.id === state) {
button.style.backgroundColor = selectedTab;
} else {
button.style.backgroundColor = otherTab;
}
});
}); // AcStatebox
}); // OnReady Function
// User IP
// function getUserIP(){
// fetch('https://extreme-ip-lookup.com/json', {
// method: 'get'
// })
// .then((httpResponse) => {
// if (httpResponse.ok) {
// return httpResponse.json();
// }
// })
// .then((json) => {
// ipAddress = json.query;
// });
// } // getUserIP
// Account Box
function loginCheck(){
if (wixUsers.currentUser.loggedIn) {
$w('#btnLogIN').label="Logout";
$w('#profileButton').enable();
}else{
$w('#btnLogIN').label="Login";
$w('#profileButton').disable();
$w('#walletButton').disable();
}
} // loginCheck
export function btnLogIN_click(event) {
// if the user is logged in
if (wixUsers.currentUser.loggedIn) {
wixUsers.logout()
.then(() =>{
// disable profile and wallet
loginCheck();
});
}
else{
let userId;
let userEmail;
wixUsers.promptLogin( {"mode" : "login"} )
.then((user) =>{
userId = user.id;
return user.getEmail();
})
.then((email)=>{
//check if the email is already exist
userEmail = email;
return wixData.query("Users")
.eq("_id",userId)
.find();
})
.then((results)=>{
if(results.items.length === 0){
let randVar = Math.floor(Math.random() * 8999) + 1000;
// create object of data to add to collection
const toInsert = {
"_id": userId,
"emailAddress": userEmail,
"verified": "Pending",
"randomNumber": randVar
// "ipAddress": ipAddress
}
// add data to collection
wixData.insert("Users",toInsert)
.catch((err) =>{
console.log(err);
});
}
setTimeout(loginCheck,500);
})
.catch((err) =>{
console.log(err);
});
}
}
Help me.
Thanks😥