Edit: I can’t even get the first name code to work by itself anymore!
Question:
Hi! So, I have figured out (with the help of others here!) how to do two things for each logged-in member on two separate custom private pages:
- Display their first name
- Display their current profile picture
The problem is, there is only supposed to be one private page—the only reason I have two separate pages, is because I can’t figure out how to combine the code snippets I have to accomplish both things on the single page!
This is the 1) code:
import {currentMember} from ‘wix-members-frontend’
$w.onReady(function () {
currentMember.getMember().then(member => {
const fname = member.contactDetails.firstName
})
$w(‘#text1’).text = 'Have a great day, ’ + fname + ‘!’
This is the 2) code:
import { authentication, currentMember } from “wix-members-frontend”;
$w.onReady(function () {
const isLoggedIn = authentication.loggedIn();
if (isLoggedIn) {
fetchMemberData();
} else {
authentication
.promptLogin({ mode: 'login', modal: false })
.then(() => {
fetchMemberData();
})
.catch((error) => {
console.error(error);
});
}
});
function fetchMemberData() {
currentMember
.getMember({ fieldsets: ['FULL'] })
.then((member) => {
$w('#memberimage').src = member.profile.profilePhoto.url;
})
.catch((error) => {
console.error(error);
});
}
So, for example in this screenshot, both the picture changes and the second “Hey” changes to the user’s first name. Again, I’ve successfully done the code on separate pages, but I don’t know how to incorporate it into one! I keep getting errors.
Thank you so much!