I have a few different datasets. I'd like to have my members only be able to see a table on their member page that relates specifically to their dataset. I've tried this code:
$w.onReady(() => {
let user = wixUsers.currentUser;
user.getEmail()
.then((email) => {
if (email === 'becca@anactofmurder.co.uk') {
$w("#table2").show();
} else {
$w("#table2").hide();
}
});
But all my members can still see the table even if their email address isn't the email address specified in the code. Any ideas?
As long as they're your site members their user id matches the owner field of the data they have created on your dataset.
You can set a filter to match the wixUsers.currentUser and the Owner id. So they can only see their own data.
If you have more than 1 dataset to show you can create an if condition to match the current user id to the owner id field of the related dataset to show and hide the tables.
Hi,
Try adding console.log(email) after the then to check what is being returned.
//... .then((email) => { console.log(email); if (email === 'becca@anactofmurder.co.uk') {
Hmm, I hadn't set it as hidden on load so now I've clicked that it isn't showing up which is what I want. But it's also not showing for that particular member, so the .show() isn't working. Any idea why it isn't matching the email up?
I don't know what the rest of your code looks like, but perhaps it's because you don't have the table hidden upon load:
If there is no user, or no email is returned, then it might be the case that the .hide() isn't run. If the table is hidden upon load, then no one sees it till the email matches and .show() runs.