Replacing default picture with member's profile picture

First success:

Hi! A while ago with help from awesome people here, I figured out how to make a default picture in the header be replaced with the logged-in user’s profile picture. I placed it on the masterpage.js in Velo. See picture and code below:

import { authentication, currentMember } from 'wix-members-frontend';

$w.onReady(function () {
    if (authentication.loggedIn()) {
        fetchMemberData();
    }
});

function fetchMemberData() {
    currentMember.getMember({ fieldsets: ['FULL'] })
        .then((member) => {
            const profilePhoto = member?.profile?.profilePhoto?.url;

            if (profilePhoto) {
                $w('#memberimage').src = profilePhoto;
            }
        })
        .catch((error) => {
            console.error('Error fetching member data:', error);
        });
}

Here is my next question:

When my user visits another user’s member’s area profile page (i.e. the one Wix automatically creates for each member), I want a dummy image to be replaced with the actual profile picture of the member the user is viewing. See below! So, for example, if “me” visits John’s profile, that cereal bowl is replaced with John’s profile picture. If “me” visits Derek’s profile, it’s replaced with Derek’s profile picture, etc. I know that the default profile page has the member picture, but it’s way too small, so this is why I want to create a custom solution with code, in the same way that I did it for the logged-in user in the header.

I would be so so grateful if anyone can figure this out! :slight_smile: I am working in Wix Editor.

To further illustrate, this is what I am trying to accomplish:

.

Nice work on the header one. For the viewed member, the page has to work out whose profile it is, then fetch that member’s photo on the backend, because currentMember only ever returns the logged-in person.

Step 1, get the slug from the URL on the profile page (frontend):slight_smile:


import wixLocation from 'wix-location-frontend';
import { getMemberPhoto } from 'backend/members.web';

$w.onReady(async () => {
  const slug = wixLocation.path[1]; // /profile/<slug>/profile
  const url = await getMemberPhoto(slug);
  if (url) $w('#memberimage').src = url;
});
```

Step 2, backend/members.web.js (needs elevation to read other members):

```
import { Permissions, webMethod } from 'wix-web-module';
import { members } from 'wix-members-backend';
import { auth } from '@wix/essentials';

export const getMemberPhoto = webMethod(Permissions.Anyone, async (slug) => {
  const elevatedQuery = auth.elevate(members.queryMembers);
  const res = await elevatedQuery().eq('profile.slug', slug).find();
  return res.items[0]?.profile?.photo?.url;
});
```

Check the real path index with console.log(wixLocation.path) first, since it depends on your profile URL setup. Also confirm Velo code can attach to your Members profile page in your editor, as that page is an app page and I'm not certain every version allows it. If it doesn't, the same backend function works from a custom profile page.

If this helped, please mark it as Solved.

Hi Ecomswift, thanks for your swift response! :wink:

I’m sorry, maybe I sounded too professional from my post above…I tried pasting your code as you put it exactly onto the page I want it (the Members Area profile page), but it didn’t work. I know that you have written that I need to replace things with my specific site details, but I really don’t know where I am supposed to do that, and what I’m supposed to do…again, I am really a coding noob. :melting_face:

If it helps, the URL of the profile page is abc.com/profile/userid/profile. [I would make it simpler if I could, but that’s not as important right now!] The default image’s ID that I want to replace is #defaultprofile.

If you could tell me the exact code that would be absolutely amazing. Again, I’m really sorry that I don’t know how to do it myself…I really, truly hope this helps somebody else, too. :blush:

Thank you!

Austin

bump! :blush:

It seems like it should be easy to do, and we’re so close…crossing my fingers! :slight_smile:

another try, asking for help…:slight_smile: