First problem - Solved
the problem probably comes from the Wix system,
and the history of DataBase Collection (Names) in my site
Right now, If I use with default login / register wixUsers.promptLogin ({“”})
When someone signs up, the standard data are sent (email, password)
After I approve him, It connects, and then the system is created for him,
the same ID & Owner (So far fine)
When he Login, he has ID & Owner,
But in dynamic page the system sends data of the last user recorded, no matter what
also in “table” i get the all users collection and not specific data from user.
Edit:
The solution is to create 1 DataSet, for all the general site, and put the DataSet in the “Footer” also set filter to “Owner” (it work for me well) and like this way, i prevent page clash.
Second problem
I’ve built a custom login/register page
https://www.aviramdayan-dreamelodic.com/login-register-page
when someone registers, he sees all the data
(first time,what that i sent in the page code after he register),
but in DataBase, sent only one item anytime in total,
and if someone else register after,
the Wix system replace the existing item (with the last one that register)
no matter what
and not create new specific item for the same user
my custom login/register page code
//=================//
// Login-Register //
//=================//
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
//import wixCRM from 'wix-crm';
$w.onReady(function () {
//======//
//Login
//======//
$w('#LoginButtonPage').onClick(function () {
//Api//
let user = wixUsers.currentUser;
let userId = user.id; // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true
user.getEmail()
.then( (email) => {
let userEmail = email; // "user@something.com"
$w('#EmailSingup').value = userEmail;
$w('#EmailLogin').value = userEmail;
});
//====//
let email = $w('#EmailLogin').value;
let password = $w('#PasswordLogin').value;
let fullName = $w('#FullNameRegister').value;
let title = $w('#MenuRegister').value;
//let isEmpty = $w("#TestDataSetRegister").getCurrentItem(); //DataSetRegister << my original DataSet
wixUsers.login(email, password)
.then(() => {
//hide register stuff
$w("#RegisterTitle").hide();
$w("#text188").hide();
$w("#EmailSingup").hide();
$w("#PasswordSingup").hide();
$w("#FullNameRegister").hide();
$w("#text183").hide();
$w("#checkbox1").hide();
$w("#SingupButtonPage").hide();
$w("#MenuRegister").hide();
//hide login stuff
$w("#LoginTitle").hide();
$w("#text187").hide();
$w("#EmailLogin").hide();
$w("#PasswordLogin").hide();
$w("#group92").hide();
$w("#ForgotPassword").hide();
$w("#LoginButtonPage").hide();
//show ThankYouText stuff
$w("#HtmlLogoNewCss").show();
$w("#SnowCss").show();
$w("#BoxLoginRegister").show();
$w("#ThankYouTextRegister").show();
$w("#ThankYouTextRegister").text = `Hello ${fullName}, You are login Enjoy.`;
$w("#TextOrangeChange").show();
setTimeout(() => {
//after go to profile page
/* wixLocation.to(`/UserProfile/${wixUsers.currentUser.id}`) << my original dynamic page location wixLocation.to(`/account/my-account`) <<< wix crm */
wixLocation.to(`/Profile/Update/${wixUsers.currentUser.id}`)
}, 7000);
})
}) //end onClick login
//==================//
//========//
//Register
//========//
$w('#SingupButtonPage').onClick(function () {
//=========//
//my custom//
//=========//
//Api//
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn; // true
let userId
let Owner
let Email
let Password
let FullName;
let Title;
let email = $w('#EmailSingup').value;
let password = $w('#PasswordSingup').value;
let fullName = $w('#FullNameRegister').value;
let title = $w('#MenuRegister').value;
wixUsers.register(email, password) //register
.then(() => {
userId = user.id; //<---//create the id value
//FullName = user.fullName;
return user.getEmail();
}) //end then "user"
.then(() => {
// check if there is an item for the user in the collection
Email = email;
return wixData.query("Profile") // UserProfile << my original data base
.eq("_id", userId)
.eq("email", Email)
.eq("fullName", FullName)
.find();
}) //end then "email"
.then((results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
"_id": userId,
"_owner": Owner,
"email": Email,
"password": Password,
"fullName": FullName,
"title": Title
};
// add the item to the collection
wixData.insert("Profile", toInsert) // UserProfile << my original data base
.catch((err) => {
console.log(err);
});
}
//hide register stuff
$w("#RegisterTitle").hide();
$w("#text188").hide();
$w("#EmailSingup").hide();
$w("#PasswordSingup").hide();
$w("#FullNameRegister").hide();
$w("#text183").hide();
$w("#checkbox1").hide();
$w("#SingupButtonPage").hide();
$w("#MenuRegister").hide();
//hide login stuff
$w("#LoginTitle").hide();
$w("#text187").hide();
$w("#EmailLogin").hide();
$w("#PasswordLogin").hide();
$w("#group92").hide();
$w("#ForgotPassword").hide();
$w("#LoginButtonPage").hide();
//show ThankYouText stuff
$w("#HtmlLogoNewCss").show();
$w("#SnowCss").show();
$w("#BoxLoginRegister").show();
$w("#ThankYouTextRegister").show();
$w("#ThankYouTextRegister").text = `hello ${fullName} , Thanks for your registering`;
$w("#TextOrangeChange").show();
setTimeout(() => {
//go to home page
wixLocation.to('/home');
}, 7000);
//=========//
})
})
//==================//
}) // end onReady
//ForgotPassword_click
export function ForgotPassword_click() {
wixUsers.promptForgotPassword();
}
//MenuRegister title hover text
export function MenuRegister_mouseIn(event) {
$w("#TextHelpMenuRegister").show();
setTimeout(() => {
$w("#TextHelpMenuRegister").hide();
}, 3000);
}
Third problem
in the “Backend” Before new Login & Before new register
I would also want to wait and do “Hooks”
and to not add new user to DataBase,
if spasific email existing, so replaced with the same item,
and not creat new item
i try this public code and it doesn't work (i twisted a little)
import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixCRM from 'wix-crm';
import wixUsers from 'wix-users-backend';
export function searchForDuplicateUsernames(value) {
return wixData.query("ProfileUser") //ProfileUser <== original database
.eq("email", value.email)
.find()
.then((results) => {
return results.items.length;
})
.catch((err) => {
let errorMsg = err;
})
}
export function searchForUsernamesIds(value) {
//This will check if the username and email is the same i.e, The username is not changed by the user
return wixData.query("ProfileUser") //ProfileUser <== original database
//.eq("_id", value.id)
.eq("fullName", value.fullName)
.eq("email", value.email)
.find()
.then((results) => {
return results.items.length;
})
.catch((err) => {
let errorMsg = err;
})
}
export function ProfileUser_beforeInsert(item, context) { //ProfileUser <== original database
return searchForDuplicateUsernames(item, context).then((res) => {
if (res > 0)
{
return Promise.reject('This username is already taken');
}
return item;
});
}
export function ProfileUser_beforeUpdate(item, context, value) {
return searchForUsernamesIds(item, context).then((res) => {
if (res > 0) {
// the user name is not change but some other value is changed
return Promise.resolve('Updated the changes');
}
else
{
return searchForDuplicateUsernames(item, context).then((res) => {
if (res > 0)
{
return Promise.reject('This username is already taken');
}
});
return item;
}
});
}
export function onUpDate(value) {
return wixData.query("ProfileUser") //ProfileUser <== original database
.eq("email", value.email)
.find()
.then((results) => {
return results.items.length;
})
.catch((err) => {
let errorMsg = err;
})
}