I have a dynamic button on my website that links to a pdf file in my database. I want to make it only available if the user has made an account. Wix says there’s currently no built-in functions for that. If anyone has some sort of workaround or can offer some assistance that would be great. Thanks .
Hi,
You can use the wix-users API to check if a user is logged in and if they are logged in, you can enable the button . For reference to the wix-users api, click here .
Best Regards,
Edward
So the only problem is that I can’t test this code without publishing, which I can’t do yet. Would this code work?
if (wixUsers.currentUser.loggedIn) {
$w( “#specsheetdownload” ).enable(); // disable or enable
} else {
$w( “#specsheetdownload” ).disable(); // disable or enable
}
Hi Marc,
That code looks like it should work but I encourage you to duplicate the site, publish the duplicated site with code and test the code just to make sure it works on the published site.
You can also check the following post answer here since it is similar to what you are trying to do here , except you will have to use the .enable() and .disable() for your button.
Best Regards,
Edward
Thanks Edward! I took a look at the code there. Is it preferable to use a function like they did or a simple if statement like I used? For reference, here’s the code I am referring to.
import wixUsers from 'wix-users';
$w.onReady(function () {
hideElem();
});
wixUsers.onLogin(() => {
hideElem();
});
function hideElem() {
let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
if (isLoggedIn) {
$w('#UserOnly').hide();
}
}