This is my first time attempting to use wix or corvid properly and I’ve pretty quickly ran into a big issue. Whenever I attempt to query my PrivateMembersData database I never get anything back, it used to return nothing since when I used console.log my result would just say ‘undefined’ however I tweaked a few things since then after realising I should be putting return before making the query etc and even though what I have put now seems like its more correct I also now have an uncaught error.
The current situation is that I still don’t think I’m getting a valid response from the database since everything past my ‘.then(result => {’ doesn’t seem to run at all, along with some errors in the console saying ‘uncaught (in promise)’ with the next line in the trace being ‘convertToErrorObject’ but then it all seems to become quite meaningless after that. When I click on the convertToErrorObject part I get this message: ‘TypeError: Cannot read property ‘requestContent’ of undefined’.
So obviously I’ve done something wrong but saying I’ve never really tried making a website before I’m quite lost as it stands. I’ll attach my code below:
Page:
import wixData from 'wix-data';
import wixUsers from 'wix-users';
import {searchForUser} from 'backend/checkAccounts'
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
var lettersNumbers = /^[0-9a-zA-Z]+$/;
$w.onReady(function () {
// TODO: write your page related code here...
});
export function signUpClick(event) {
// Add your code for this event here:
$w("#user").onCustomValidation( (value, reject) => {
console.log(value);
searchForUser(value)
.then(result => {
console.log("Value ", result);
if (result === "FOUND") {
console.log("User exists");
reject("Invalid username.");
$w("#errorText").text = "Username already exists.";
}else {
console.log("User doesn't exist");
if (!value.match(lettersNumbers)) {
reject("Invalid username.");
$w("#errorText").text = "Username must only contain letters and numbers.";
}
}
});
});
}
The backend ‘checkAccounts’ web module:
import wixData from 'wix-data';
// Filename: backend/checkAccounts.jsw (web modules need to have a .jsw extension)
export function searchForUser(user) {
return wixData.query("Members/PrivateMembersData")
.eq("name", user)
.find()
.then( (results) => {
if (results.items.length > 0) {
return "FOUND";
}else {
return "NORESULTS";
}
});
}
If anyone knows what I’ve missed any help would be greatly appreciated.