Linking to a 'currentUser' site member profile card

Hi there, any help I can get will be much appreciated!

I’ve been using the following code to create a 'c ustom member log in page '.

However, when the ‘Profile’ button is clicked, I want the event handler to send members to their personal PROFILE CARD - NOT a profile page I created - but the standard WIX member profile page /card that comes with the ‘Member’s Area’ Wix app.

Does anyone know if this is at all possible and if so, how to achieve it?

Basically what I need is a piece of code (an event handler) that sends visitors (logged in members) to their own WIX PROFILE CARD upon clicking it.

Many thanks in advance to all good souls able to help out! Below is the code I~m trying to work with…

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w(“#button4”).label = “Logout”;
$w(“#button5”).show();
}
else {
$w(“#button4”).label = “Login”;
$w(“#button5”).hide();
}
} );
export function button4_onclick() {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#button4”).label = “Login”;
$w(“#button5”).hide();
} );
}
// user is logged out
else {
let userId;
let userEmail;

// prompt the user to log in
wixUsers.promptLogin( {“mode”: “login”} )
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“MemberProfile”)
.eq(“_id”, userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
“_id”: userId,
“email”: userEmail
};
// add the item to the collection
wixData.insert(“MemberProfile”, toInsert)
.catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#button4”).label = “Logout”;
$w(“#button5”).show();
} )
.catch( (err) => {
console.log(err);
} );
}
}
export function button5_onclick() {
wixLocation.to(/MemberProfile/Update/${wixUsers.currentUser.id});
}

1 Like

Hi Tiago,

Where it takes you when you click on button5 ? because the problem should be with the URL you redirecting to!

export function button5_onclick() {
wixLocation.to(`/MemberProfile/Update/${wixUsers.currentUser.id}`); //THIS
}

be sure that you have made a dynamic page and also be sure to make the ID as a unique field.

Try to follow this guide more closely to make the wixLocation.to works.

GoodLuck.

Mustafa

Hi Mustafa,

Thanks for getting back to me.

It takes me to a dynamic page I’ve built - so, the code works OK - but that’s not what I need. I need a code to take members to their own profile card (created by the WIX Member Login App) already installed and running on the site…

https://www.wix.com/app-market/member-login-app/overview

Is it possible?

Many thanks,
Tiago

1 Like

Hi Tiago,

I’m not familiar enough with this app. However, Wix has a new built-in members area functionality that you don’t have to install from the app market.
If you click the Plus button in the editor, you will see Members elements. There are login bar, profile cards and more.
After you add the login bar, you will also have Member Pages under the Pages button. There is a built-in page called My Account, and you can add more pages of your own. The default URL for My Account is /account/my-account without any memberId in the URL.
So if you switch to that new membership app, which I guess is a good idea because this is the one that Wix are actively working on and adding more features to, you can use
wixLocation.to(“/account/my-account”);

You might want to test that functionality on a test site before you invest in replacing your members app just to make sure that it has everything that you need.

2 Likes

Hi Dan,
that’s BRILLIANT! That’s exactly what I needed to know re: the wixLocation.to (“/account/my-account”); function! THANKS A LOT FOR YOUR INPUT!!!

Pushing my luck a bit now - would you happen to know if I can control WHEN the ‘LOGIN BAR’ shows up, please? What I’m trying to do is have the LOGIN BAR display ONLY when a member is already logged in. It must not show when a visitor is not yet logged in…

THANKS A LOT FOR YOUR HELP - I HAVE SPENT A LOT OF TIME LOOKING UP FOR THIS SOLUTION!

Best,
Tiago

2 Likes

I guess you can do $w(“#accountNavBar1”).show() (or hide) where ever in your code you’d like to show it.
You can control the initial visible/hidden state in the properties panel of the login bar (right click on it), using the “hidden on load” checkbox.
Note that if you hide on load, users that are already logged-in and just refresh the browser will have hidden bar. To make sure this doesn’t happen you’ll have to call .show() also in $w.onReady(…) if wixUsers.currentUser.loggedIn is true.

2 Likes

Thanks again, Dan. Will explore this option today!
Cheers for that!
Tiago