Hey there! I need a button to take each of my site members to a different link.
I have a site member area, but the collection is read only, so I created another collection with the same email and a corresponding link. I simply want the link of a button to change according to which site member is logged in.
But I can’t for the life of me get this to work. I tried doing this with a reference field, but it wouldn’t work, and then I tried this code:
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixUsers from 'wix-users';
import wixData from 'wix-data';
let user = wixUsers.currentUser;
$w.onReady(function () {
user.getEmail()
.then( (email) => {
let userEmail = email;
console.log(userEmail);
wixData.query("Links").eq("email", userEmail).find()
.then( (results) => {
if(results.items.length === 1) {
let userLink = results[0].link;
console.log(userLink);
$w("#linkButton").enable();
$w("#linkButton").link = userLink;
} else {
$w("#linkButton").disable();
}
} )
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
} );
});
This works out well when I preview, but when I test it live the button is never enabled… 
I’m very new to this, I know my code might not be very efficient so if anyone has a better idea of how to do this I would greatly appreciate your help! 
Natalia,
A couple things to consider.
I’m not sure how it’s working when you preview because the userLink assignment syntax isn’t quite right. The data that is returned is in the items array within results. So, this would be the link of the first item:
let userLink = results.items[0].link;
After changing this, I’m wondering if you will still receive different results in preview as opposed to the live page. If so, I would check that the contents of the Links collection is exactly the same in the live version as it is in the sandbox?
Hello Anthony, thank you for your help!
It appears that now my button is enabled but when I click it it doesn’t redirect me anywhere
I thought it might be because I’m not telling wix what should happen when I click the button. So I added this piece:
export function linkButton_click(event) {
wixLocation.to($w("#linkButton").link);
}
It does nothing so I’m not sure what’s going on here…
Do yo have any clue of where I might be missing something?Or maybe a better way to implement this?
Thanks
What does console.log(userLink) return in the developer console at the bottom?
You might verify that the linkButton onClick event is still “registered” in the property sheet as follows. If you don’t see “linkButton_click”, then the code block above will do nothing.

The console.log(userLink) returns the link I want to go to. I made sure that the onClick event is registered in the properties panel, but still when I go on live it doesn’t lead me to my link…
It doesn’t matter how much times I click nothing happens. I already made sure to specify the target of the button with
$w("#linkButton").target = "_self";
But it doesn’t help either…
I’m trying to do the same thing, so if anyone has more input, that would be fantastic 