Get member ID of current profile

I want to add elements to a public profile page, based on who that user is. I need to know which member’s profile page it is, in code.

For example
I’m logged in as ‘Member A’ and viewing 'Member B’s profile. What is Member B’s ID?

Instead of wixUsers.currentUser.id
I want wixUsers.currentProfile.id (Not a real API, looking for equivalent of this)

I have to be missing something, this seems so basic.

Is there no way to add info to a member profile through code?

Disappointing if this is really not available.

Public profiles become (edited: Ok, not useless, just underwhelming) .

I’m looking for the same thing this evening. I’ll drop back in if I find it.

Got it.
User slug *should * be unique.
This is working so far.
Get it, then query private members data in a backend module.

Front ent

import wixLocation from 'wix-location';
import { getSomeone } from 'backend/getAboutMe';

let myData;
let curSlug;

$w.onReady(function () {
    getData();
});

function setSlug() {
 let cur = wixLocation.path;
    curSlug = cur[0];
}

async function getData() {
    setSlug();
 try {
        myData = await getSomeone(curSlug);
        myData.doesWhatYouNeedNext
}

Backend

import wixData from 'wix-data';

export async function getSomeone(slugIn) {
 try {
 let qres = await wixData.query('Members/PrivateMembersData').eq('slug',slugIn).limit(1).find(qopts);
 let id;
 if (qres && qres.length > 0) {
            id = qres.items[0]._id;
        } else {
 return;
        }
 let dataOut = getSomeOtherDataHere(id)
 if (dataOut) {
 return dataOut;
        } else {
 return false
        }
    } catch (err) {
        console.log(err);
 return false;
    }
}

So, while this works, I still prefer to use dynamic pages. It keeps us in clear control over access and content. In this case I had a client with this as a requirement.

Hi Robert,

Thanks a lot for the replies, glad to see I wasn’t alone. I went with custom dynamic pages as well.

Using the slugs is a nice solution for the other way which I hadn’t found.

It does require a query on page load though, which makes using slugs a bit slower as well unfortunately.

@derekmoorer very true. Could probably be made faster with router data, but for a quick job on a member’s page I’m not about to go through that much trouble :joy:

I found the best way of doing this is by creating a dynamic (all, and item) page for the PrivateMembersData database.

This then allows you to pull the following code

$w.onReady(function () {
let user = $w("#dynamicDataset").getCurrentItem()
let id = user._id
console.log(id)
});

Which is much simpler then trying to do it from a members page.

I’m struggling with this one, what is “qopts” in the find() query?

I’m also getting an error that there’s a catch expected with the first “try”.

@whereisshy my bad - I pulled some of the additional stuff I’m using out of this.

qopts is just me not wanting to type so much when I have many queries in one module.

const qopts = { suppressAuth : true };

This works for me. Maybe only because all of my site members are set to public profiles by default, but I don’t think wix gives them a profile page if they’re not? (I’m not sure).

I noticed that depending on where a profile page is linked from, sometimes instead of the slug, the site path uses the user’s ID. So this code looks for both, and returns the information accordingly.

$w . onReady ( function () {
let cur = wixLocation . path ;
let curSlug = cur [ 0 ];

wixData . query ( “Members/PublicData” )
. eq ( “_id” , curSlug )
. find ()
. then ( ( results ) => {
if ( results . length > 0 )
{ let currentProfileId = curSlug;
let currentProfileMember = results . items [ 0 ];

  //reference profile member here: 
  //$w("#textElement").text = currentProfileMember.nickname; 

  } 
  **else** { 
     wixData . query ( "Members/PublicData" ) 
    . eq ( "slug" , curSlug ) 
    . find () 
    . then ( ( results2 ) => { 
    **if** ( results2 . length  >  0 ) 
    { **let**  currentProfileSlug  =  curSlug; 
    **let**  currentProfileMember  =  results2 . items [ 0 ]; 

  //reference profile member here: 
  //$w("#myText").text = currentProfileMember.nickname 

  } **else** { 
      //what happens if neither slug nor ID was found in Query: 
      // $w("#myText").text = "No Username Found" 
      } 
    }) 
  } 

})
});

Many thanks