wixlocation.to(custom dynamic member profile page)

Hi,

I have made a custom login"bar" with a button that should redirect to the custom dynamic member profile page that’s ment for the member author to view and edit only. But I can’t seem do redirect it. I’m getting a 404 error. The code below must be incorrect I think. I’m totally new to coding. Although i understand the logic behind coding, I can’t come up with the codes myself. The custom dynamic page I want the button (textMijnAccount) to go to is: /leden{ID} and the {ID} must be the _id from my custom database: Leden. It does look like it now uses the ID from the PrivateMemberData. But I don’t want that. Both ID’s are also totally different.

Can someone please help me!?

import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
import wixLocation from ‘wix-location’ ;
import wixWindow from ‘wix-window’

$w.onReady( () => {
$w( “#button5” ).onMouseIn((event) => {
$w( ‘#boxInloggen’ ).expand();
});

$w( "#boxInloggen" ).onMouseOut((event) => { 
     $w( '#boxInloggen' ).collapse(); 
}) 

if (wixUsers.currentUser.loggedIn) {
$w( “#textInloggen” ).label = “Uitloggen” ;
$w( “#textMijnAccount” ).expand();
} else {
$w( “#textInloggen” ).label = “Inloggen” ;
$w( “#textMijnAccount” ).collapse();
}
$w( ‘#textMijnAccount’ ).onClick(event => {
});

$w( ‘#textInloggen’ ).onClick(event => {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then(() => {
// update buttons accordingly
$w( “#textInloggen” ).label = “Inloggen” ;
$w( “#textMijnAccount” ).collapse();
wixLocation.to(/home);
});
}

// prompt the user to log in
wixWindow.openLightbox( “inloggen” )
$w( “#boxInloggen” ).collapse()

// update buttons accordingly
$w( “#textInloggen” ).label = “Uitloggen” ;
$w( “#textMijnAccount” ).expand();

})}) 

export function textMijnAccount_onClick() {
wixLocation.to( “/leden/{ID}” );
}

wixLocation.to("/leden/" +  wixUsers.currentUser.id);

Yes, allready tried that. It seems that it then again takes the ID from the PrivateMemberData. Whatever I change the wixLocation.to(/XXX) into, in public view the URL keeps containing the ID from the PrivateMemberData and the page keeps displaying the 404 error.

@dedieetboodschapper what you’re trying to do? Anyway the code you published is wrong since you have to use a variable that reflects the desired path while you wrongly redirected to a path string “{ID}”.
Sp first decide to what path you wish to redirect and the use it:

let path = "someuserid";
wixLocation.to("/leden/" + path); 

@jonatandor35 I can’t post my reply. It keeps saying I’m not allowed to post a link, eventhough I don’t have a link in my reply.

@dedieetboodschapper So post it without the link and explain in words.

@jonatandor35 :see_no_evil: I don’t have any link in it, so that’s why I don’t know what to remove from my text. God, I’m feeling so dumb right now. I’m trying it over and over again, every time with just text and every time different text. But it keeps saying I have a link in it, but I really don’t. But I’ll try again.

So I tried the code that you said. I want my button to redirect to a custom dynamic page. The URL is called … / leden / {ID} and the ID being from my custom database Leden. But it somehow takes the ID from the default database PrivateMemberData.

This is the page I want it to redirect to:

Hi :raised_hand_with_fingers_splayed:

I assume that the custom database has unique identifier field for each member, for example, their login email, so you should query the database with that field, and get the _id of that member on that custom database.

$w('#login').onClick(() => {
    wixUsers.login(email, password).then(async user => {
        await wixData.query('collection').eq('email', email).find().then((x) => {
            if (x.length > 0) {
                const member = x.items[0];
                // Now direct the user to its profile
                wixLocation.to(`/leden/${member._id}`);
            }
        })
    })
}

Hope this helps~!
Ahmad

Thank you Ahmad,

And where should I put this inside my code? When I change is to member._id is says member is not defined.

It is not when they login by the way. It’s the button after login, where they click on to go to their profile page…

@dedieetboodschapper After they login? Or when they’re logged in?