Hi
I just write to ask experts if i have chosen best solution becasue i need to use variable in many function on pages and dont want to take each time i need
-
i need to use email to check who is logged in and then filter all pages by email. BEfore i did it by id of user but i realized that when i need to change some datas i can not put someone id. Its logical because i’m not owner. But some pages needs i also put some data but then there is my id.
-
so i will filter then by email and when insert data add email of user. Is it best way to use like global variable to use users email
i create email variable —> i make function to return email. → after onready i start function . -
then i can use email of user in all function on page without finding each time inside function.
MY QUESTION is is it best way to do it or maybe session or backend . I’m asking becasue i will use user’s email maaaaaaaaaaaaaany times and it should be stable and quick.
code
let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn; // true
let email
function findemail(){
if (isLoggedIn) {user.getEmail()
.then((email1) => {
email = email1;
// console.log(email);
return email
});}
}
$w.onReady( function () {
findemail();