404 error - link to dynamic page not working

Hello,

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?

Have you taken a look at this article: CMS (Formerly Content Manager): Troubleshooting Dynamic Pages Issues | Help Center | Wix.com?

Yes, but it has not helped. This is my first attempt at coding so it’s likely I have not done something correctly. Code is as follows:

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

$w.onReady( () => {
if(wixUsers.currentUser.loggedIn) {
$w(“#button2”).label = “Logout”;
$w(“#button1”).show();
}
else {
$w(“#button2”).label = “Login”;
$w(“#button1”).hide();
}
} );

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});
}

Hi,
Can you please share your site so we can inspect ?
Roi

https://laurenknott.wixsite.com/mysite-1

Hi,
It looks like permission issue.
The wixLocation.to is working but no item is added to the collection when signing up.
My guess is “Who can create content for this collection” doesn’t set properly.
Check this out:
https://support.wix.com/en/article/how-to-set-permissions-for-a-database-collection
Good luck
Roi

I have tried changing all the permissions on the collection to anyone, and it still gives the 404 error

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 x_lk_x !
I’m in the same situation as you.
did you find the solution?
thank you

I would like to thank you because it work and share with you my happyness!
i did 2 actions :

  1. i change database collection permissions as well :
  • Collection type : Custom use
  • Who can read : Site member
  • Who can create : Site member
  • Who can update : site member author
  • Wo can delete : site member author

2)in the database collection : i click on “sync” then “edit live database” and “live”

I hope this will be useful to you !
Let me know if i can help you …

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

This post is old and being closed.