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’
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 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.
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}`);
}
})
})
}