How to get user ID of profile that you are currently viewing

Hi, I am using the standard Wix Forum where each member has their own profile page. I want to get the user ID of the profile page currently being view (not the user Id of the current user).

For example:
My website has 2 members

  1. Myself
  2. John

When I view John’s profile (through the member’s search) I want to get John’s user Id like
“ab0f5e12-cb5f-42e3-89c5-83781a73c4a1”

When I view My profile I want to get my user Id like
“54a454cb-000a-44d9-9b32-dafa0476sd59”

Thanks,
Matthew Thomas

import wixUsers from 'wix-users';
2
3// ...
4
5let user = wixUsers.currentUser;
6
7let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
8let isLoggedIn = user.loggedIn; // true
9
10user.getEmail()
11  .then( (email) => {
12    let userEmail = email;      // "user@something.com"
13  } );
14
15user.getRoles()
16  .then( (roles) => {
17    let firstRole = roles[0];
18    let roleName = firstRole.name;                // "Role Name"
19    let roleDescription = firstRole.description;  // "Role Description"
20  } );
21
22user.getPricingPlans()
23  .then( (pricingPlans) => {
24    let firstPlan = pricingPlans[0];
25    let planName = firstPlan.name;          // "Gold"
26    let startDate = firstPlan.startDate;    // Wed Aug 29 2018 09:39:41 GMT-0500 (Eastern Standard Time)
27    let expiryDate = firstPlan.expiryDate;  // Thu Nov 29 2018 08:39:41 GMT-0400 (Eastern Daylight Time)
28  } );

This returns the current user, not the userID of the profile being viewed, also nice ag-grid on your website. I love those guys

@matt39291
Where do you store the Profile-ID of a user?

I don’t think that there is a Profile-ID, I need the userID of the user’s profile being viewed not of the current user.

1 Like

Hi Matthew
Did you succeed in getting the ID of the user’s profile being viewed. I need to do the same to implement a filter.
Many thanks

Hi, I don’t know if you guys found a solution for this. I also wanted to do the same so it would be much appreciated if someone instruct us in this problem.
Thank you.

What you can do is that you can get the profile slug from the page.

const slug = wixLocation.path[0]; // Assuming URL structure: /profile/{slug}/profile
if (slug) {
loadProfileBySlug(slug);
}

async function loadProfileBySlug(slug) {
const memberData = await wixData.query(“Members/FullData”)
.eq(“slug”, slug)
.find();
}

The slug is unique, so you can then use it to query the memberData from the slug.

Then you can implement any custom logic as you have the userID which is (and should be) your main reference for most of your databases.

Note, you can only query the FullData database without user being logged in.