Hello,
On my first page just after loggin, for some reason, the code is not applied…
If I reload the page manually (just click enter in the URL, the code is working!)
See below just to hide or show a button depending to a wixdata query.
Thanks
regards
Pierre-yves
$w.onReady(function () {
let user;
user = wixUsers.currentUser;
$w("#adminButton").hide();
user.getEmail().then((email) => {
let userEmail = email;
$w("#email").text = userEmail;
let count;
wixData.query("clientDataset")
.eq("title", userEmail)
.eq("userStatus", "active")
.hasSome("userType", "pilot", "system")
.find()
.then((results) => {
//console.log(results);
count = results.totalCount;
//console.log(count);
if (count >= 1) {
$w("#adminButton").show(); // NOT WORKING ON FIRST LOAD – WORKING WHEN RELOADING URL
} else {
$w("#adminButton").hide();
}
})
.catch((err) => {
let errorMsg = err;
console.log(errorMsg);
});
});
});
hello,
You're right, the issue is there... This is because I am not registred yes when logging...
With the new right this is working !!!
Sounds like a bug, because the login object should be completed before I have got access to the member page...
Nevertheless this is working and this change does not creates any permission side effect from my understanding...
Once again, thanks for your time
Regards,
pym
Regarding the permissions error...
When someone shows up the first time, they are not a "registered user". At least, the site doesn't realize that until they've logged in. So, it seems to me that the proper permission setting for "Who can read content from this collection" should be Anyone. The problem might be that the error you are getting is because the "current user" is not logged in yet, and therefore is an "anyone", and not yet a "site member".
Does that make sense?
Hey Pym,
Good hearing from you again, although sorry to hear it's not working.
Just saw your last post as I was typing this - I'll need some time to read and understand.
Meanwhile, please put the login credentials somewhere (a backend file is the most secure place).
I'll see if I can work things out.
Yisrael
Hi Yisrael,
I forgot to provide important information regarding this issue.
On the first logging, my issue is a button is not visible – As you can see in the code this is based on a dataset query on my dataset clientdataset.
1 – I found out in the developer console, I have the error:
Failed to load initial data Error: The current user does not have permissions to read on the clientDataset collection.
Error: The current user does not have permissions to read on the clientDataset collection.
2 – When reloading the page (just clicking enter in the address, I don’t have the error and the button appears.
What I don’t understand, the current user has the right on clientdataset.
An idea what’s going on?
Regards,
Pierre-yves
Hi Yisrael,
How are you ?
I have still my login issue, when logged on a first time to the member page… I am pretty sure this is a performance issue/time out issue. I have the same behavior with firefox and IE. Have you got chance to look to the url finally ? Did you succeed to connect?
Thanks for your help Regards, Pym
Hello yisrael,
Sorry for the delay replying.
Correct there was an error in the password, i just tested and should work now.
Let me know if there is any issue.
Regards,
pym
OK, cloned it.
Tried to login with the credentials you supplied but it says wrong email or password.
Hello Yisrael
I just added it in the code as comment
Regards,
pym
I don't need a dev profile since I can clone the site and play with it without messing up any of your stuff.
Just add the login credentials as a comment in the page code and I'll look at it as soon as I can.
Hello Yisrael,
Once again, thanks for your help.
I copied your code, same story, first time it worked in a new tab, I logout then re login and not worked the second time ;(
Sorry, I did not catch your idea to paste the password in my code, if you want I can send my user/pass by email ?
Can I create a new dev profile for you ? (not sure I will succeed, I never done than before)
Regards,
pym
Well, I wanted to put some debug statements - console.log() - in the code and try to figure out what's happening.
However, I think the logic just needs a tweak...
$w("#clientDataset").onReady(() => { user.getEmail().then((email) => { let userEmail = email; $w("#email").text = userEmail; wixData.query("clientDataset") .eq("title", userEmail) .eq("userStatus", "active") .hasSome("userType", "pilot", "system") .find() .then((results) => { let count; count = results.totalCount; if (count >= 1) { $w("#adminButton").show(); } else { $w("#adminButton").hide(); } }) .catch((err) => { let errorMsg = err; console.log(errorMsg); }); }); });
What you want is that when the dataset is ready, the dataset's onReady function triggers and runs your code.
If this doesn't do it for you, then just put a working sample login credentials as a comment in the page code.
Yisrael
Can I send it to you per mail ? I don t see how I can embed the code in the page code... You just need a client profile to access or do you need to see code as well ?
pym
Do you have a login I can use? You can embed it in the page code so no one else will see it but me. Just tell me where you put it.
hello Yisrael,
here is the url
https://www.think4jet.com/members
thanks
pym
Hi Pierre-yves,
Post your URL so I can inspect.
Hi Yisrael,
Unfortunately, I guess this is more insidious than I expect...
I already put my code on a dataset ready function, and this is still not working "everytime"
1 - When I open a new tab, login to my website and go the the page, this is working !!!
2 - If I apply the same process (login to my website) in a current page and not a new one, this is not working...
Sounds like the issue is not linked to my code...
If you have any idea what s going on I am interested !
Thanks
$w.onReady(function () {
let user;
user = wixUsers.currentUser;
$w("#adminButton").hide();
user.getEmail().then((email) => {
let userEmail = email;
$w("#email").text = userEmail;
$w("#clientDataset").onReady(() => { ....
Your problem may be because the dataset hasn't fully loaded when your code runs. Take a look at the forum post Datasets have an onReady function.