Hello,
on our website www.philippe-karl.com, I created a member log in function with Wix Code. After registering under Philippe Karl and being approved, members are allowed to create their personal profile through a dynamic page. These profiles are displayed on the subpage https://www.philippe-karl.com/licensed-teachers.
This worked perfectly well until we launched the site a few days ago. Now users can log in but they report getting a 404 Error when trying to create their profile (getting to the form on the dynamic page, that is).
For members who created their profiles before the site was launched under the current domain, there is no problem to access and to modify their data. I could not find the bug in the code of the site nor in an unexisting URL.
Hey Tiaan,
thanks so much for commenting! I am sorry, I don’t get what you mean by ‘linking through the user interface’… It worked perfectly well before transferring the domain to WIX, and directly after the transfer it gave the 404 error. I couldn’t identify an error in the code - I am clueless.
No worries… What I’m basically asking is whether you’ve connected the button by clicking on it then linking it through the small icons that pop up, or whether you’ve connected the button with code to go to your page?
So for example “www.riding-simulator.co.uk” probably needs to be “https://www.riding-simulator.co.uk”.
The same goes for the other urls. You may need to write some code that prepends the https:// string after checking that it doesn’t already exist.
Hi Tiaan, hi Steve!
thanks again for putting so much effort into this matter. I feel like it is an obvious an silly mistake I just can’t see… Anyhow, here ist the code for the Teacher Log In Page.
Your code looks absolutely fine…, I would need to take a look inside your site give you a solution for this. Alternatively, since you are on a paid plan, WiX Premium Support should help you out…
Sorry I just got my head around the problem you are having.
The profile page appears to be loading through a router - ‘Update’ right?
The logic in your router is what we probably need to see to help you debug this.
My guess is that there is a disconnect between the wixUsers.currentUser.id and the ids stored in your TeacherProfile data collection. There was a similar post by another developer where they we finding multiple records with common key data (not necessarily the id but they were looking at other info like email address) in their database which resulted in their validation logic failing.
I would look at the router code and database records with the id and see if this is an issue. If you share the code in Update that would also help us help you further.
What data is added to the ‘TeacherProfiles’ data collection and when, how it is subsequently used or updated. So for example
How is the original TeacherProfiles data collection record created?
Per our offline discussion. If you change line 42 in your code example above to .eq(‘eMail’, email) then that will at least bind the logged in user from wix-users/wix-crm to your TeacherProfiles data collection.
Once you have the results from the TeacherProfiles data collection you need to use that information to drive your User Profile button code so it is probably a good idea to remember what was retrieved from the find() request by adapting the promptLogin result like so:
//************************************************
// Add this code to remember the found record! //************************************************
let teacherProfileRecord = null;
export function button1_onclick() {
// user is logged in
teacherProfileRecord = null; // reset the teacherProfile record
if(wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w("#button1").label = "Login / Register";
$w("#button2").hide();
} );
}
// user is logged out
else {
let userId;
let userEmail;
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("TeacherProfiles")
.eq("eMail", email)
.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("TeacherProfiles", toInsert)
//************************************************
// Add this code to remember the found record!
//************************************************
.then((insertedRecord) => {
// Enable member actions
loginSuccessful(insertedRecord);
})
.catch( (err) => {
console.log(err);
} );
//************************************************
// Add this code to remember the found record!
//************************************************
} else if (results.items.length === 1) {
// Enable member actions
loginSuccessful(results.items[0]);
}
} )
.catch( (err) => {
console.log(err);
} );
}
}
//************************************************
// Add this code to remember the found record! //************************************************
function loginSuccessful(teacherProfile) {
if (teacherProfile) {
// Remember the user record for dynamic page generation
teacherProfileRecord = teacherProfile;
// update buttons if successful
$w("#button1").label = "Logout";
$w("#button2").show();
}
}
Now to load the dynamic pages you can just get the page URL from the TeacherProfile record like so
export function button2_onclick() {
if (teacherProfileRecord && teacherProfileRecord['link-TeacherProfiles-Update']) {
wixLocation.to(teacherProfileRecord['link-TeacherProfiles-Update']);
}
}