Hi,
This page shows details of each of our member (let's say 100 members). I am member #20, I can see my own details as well as all other 99 members details.
I have created an editable allowing me to revise my details. This page can open when clicking the 'Revise your Profile' button. This button is actually Hidden on load and I want it to only appear only when I am looking at my member #20 profile (in consequence, this button will not appear when i am looking at all other 99 members page).
In short, it will allow each member to revise it's own details but not other members details.
Can anybody help me with the code needed for this button to appear only for the registered user that is logged in the site?
Thanks a lot.
Gotcha!! Thanks a lot. I am almost done in my development. Still one last page for which I might post another assistance request.
You don't need the lines that are outside the onReady (except for the import statement line).
Try deleting:
let user = wixUsers.currentUser; let userEmail; user.getEmail() .then( (email) => { userEmail = email; } );
It should not be very far from working but it still is blocked (the field is 'email' while the data connection ID is 'dynamicDataset'). The 'Hideen on Load' button ('button2') is on a Dynamic Page.
Coding page below:
import wixUsers from 'wix-users';
let user = wixUsers.currentUser;
let userEmail;
user.getEmail()
.then( (email) => {
userEmail = email;
} );
$w.onReady(function () {
$w("#dynamicDataset").onReady( () => {
let currentEmail = $w("#dynamicDataset").getCurrentItem().email;
wixUsers.currentUser.getEmail()
.then( (email) => {
if(email === currentEmail) {
$w("#button2").show();
}
} );
} );
} );
The console shows
- There was an error in your script
- TypeError: t is undefined
but I cannot figure out what ...
Thanks a lot
Hey again,
First off, the code you posted is mostly fine, but you cannot get the email address that way. Since the getEmail( ) function returns a promise you will need to do something like this:
let userEmail; user.getEmail() .then( (email) => { userEmail = email; } );
Second, with regards to the matching, it depends how your page is built. Assuming you have some sort of dataset on the page, you can get the current item and match the email for example. So altogether in the page's onReady, something like this (changes the code from above slightly):
//inside the page's onReady $w("#myDataset").onReady( () => { let currentEmail = $w("#myDataset").getCurrentItem().fieldKeyOfEmailField; wixUsers.currentUser.getEmail() .then( (email) => { if(email === currentEmail) { $w("#myButton").show(); } } ); } );
Of course, you need to change the element IDs and the field names to match the ones in your site.
I am not very good coding ... I figured the code to determine user ID and email (below) but do not know how to condition the appearance of this button to the matching of these iD and email? Can you kindly assist?
import wixUsers from 'wix-users'
;
$w.onReady(function () {
let user = wixUsers.currentUser;
let userId = user.id;
let email = user.getEmail();
Thanks and rgds,
Hey there,
You can get the current user's ID and email address using the wix-users API. You can match that information to what is being displayed in the the page or in the URL if it is a dynamic page.