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}");
}
Hi 🖐
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
wixLocation.to("/leden/" + wixUsers.currentUser.id);