I have followed the tutorial to set up a member login page, and published the site. However once I’m logged in, and I click on the “my profile” button I get a 404 error page rather than my dynamic page. I’ve tried starting again with the coding and I’m still having the same issue. Is there anyone who can take a look for me and help with a fix?
export function button2_onclick() {
// user is logged in
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#button2”).label = “Login”;
$w(“#button1”).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("profile")
.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("profile", toInsert)
.catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w("#button2").label = "Logout";
$w("#button1").show();
} )
.catch( (err) => {
console.log(err);
} );
}
}
export function button1_onclick() {
wixLocation.to(/profile/Update/${wixUsers.currentUser.id});
}
It looks like when a new user registered they are not being assigned a user ID, so when you then try to access the dynamic page to enter your profile information the page cannot be found because you have no unique ID.
Hi guys. I had the same error, but found a rather simple solution.
Press the “sync” button on the database page to sync the sandbox database to live. After that the link works.
Cheers