Hello all,
i am having a problem in comparing IDs from my userProfile database.
Each user is stored with its own id, let's say...
my ID is ca97c31f-8f52-456e-bc2e-482fe06c690d
User A is ID c9d99e9b-3694-4db8-9c01-0827e9571255
Every user profile is loaded in a dynamic page that contains a button (Edit Profile)
What i am trying to do is : if I visit my own profile page (based on the ID), the button is enabled, while if i visit User A profile page the button is disabled.
I was thinking to use a comparison between my user ID (the visitor) and the User A ID (the visited profile), something like:
if my ID = userA ID then
$w("#button2").show() //the button appears only if i visit my own profile (IDs are equal)
else
$w("#button2").hide() //the button disappears if i visit another user's profile (IDs are not equal)
but honestly don't know how to gather the IDs and set the if cicle...
Anyone can help?
Hi Alessandro Demontis
Is this what you are trying to do ? ->
You have a 'userProfile' database.
The owner field of the database can't be used because, you created the fields.
The _id field, is the field, which stores the userId of the users.
You have a dynamic page.
In the dynamic page, there is a button.
If the current user's id matches that of the dynamic page item (_id) then button should show ...
If this is, then ->
#dynamicDataset - dataset of the dynamic page.
#button2 - button to show/hide.
import wixUsers from'wix-users'; $w.onReady(function () { let user = wixUsers.currentUser; let userId = user.id; let itemUser = $w('#dynamicDataset').getCurrentItem()._id; if(userId === itemUser) { $w('#button2').show(): } else { $w('#button2').hide(): } });
One more ,
Wixusers.currentUser does not return the _owner field of the database, but returns the userId of the person who is viewing your site right now..
currentUser
Gets the current user viewing the site.
Gets a User object containing information about the user currently viewing the site.
For reference - > https://www.wix.com/corvid/reference/wix-users/introduction
First of all get the current item (userId) from the dynamic dataset.
Then, get the current user Id.
Compare using if-condition.
#dynamicDataset - Dynamic dataset of the Dynamic Page
#buttton2 - Button
import wixUsers from 'wix-users'; $w.onReady(function () { let user = wixUsers.currentUser; let userId = user.id; let id = $w('#dynamicDataset').getCurrentItem().userId; if (userId === id) { $w('#button2').show(); } else { $w('#button2').hide(); } });