In trying to create a custom registration form, I noticed a problem when I was trying to query the Collection Member to see if there was already a member with the same Email. This is Code:
Is this code in front end? I’m having a similar issue as well, and I noticed you can’t access that particular database when the code’s in front end unless you’ve logged in. To make this work you’d need to have the code in the backend then call it from the front end.
import wixData from 'wix-data';
export function ControlloEmail(Email) {
wixData.query("Members/PrivateMembersData")
.eq('loginEmail', Email)
.find()
.then( (results) => {
if (results.totalCount === 0) {
return true;
}
});
}
In Fornt End:
import {ControlloEmail} from 'backend/formRegister';
function ControlloMail () {
CheckMail ($w("#InputMail").value)
.then(function(stato) {
console.log('Stato da BackEnd - ' + stato)
});
}
}
In this case it works in Live, but as there is no return from the promise, the query is resolved late.
So I also made the last attempt with async & await because I had the doubt that .then could not work in backend (it was to remove all doubts)
FormRegister.jsw file in back-end:
import wixData from 'wix-data';
export async function CheckMail(Email) {
const results = await wixData.query("Members/PrivateMembersData")
.eq('loginEmail', Email)
.find();
// the next line will run only after the query has finished
if (results.totalCount === 0) {
return true;
}
}
In Fornt End:
import {ControlloEmail} from 'backend/formRegister';
function ControlloMail () {
CheckMail ($w("#InputMail").value)
.then(stato =>
console.log('Stato da BackEnd - ' + stato)
);
}
}
but also how the first preview case works while in Live it doesn’t work
There are no hours that I read the forum and do tests.
As I understand it, return should work, but in my case it doesn’t work. I tried to query other collections from backEnd by entering return in the query but it doesn’t work
I tried a fee other proofs, and in the end I realized that it is a problem of permissions of the “PrivateMembersData” collection, which can only be read if it is a admin or a site author.
There’s nothing you can do if you can’t get the user to log in first. So what I’ve done for my website was I made a custom sign up form that will send the user’s name and email to my own database. After signing up the page will log the user in, at which point their current id will also be updated in my database.
The pseudo code for it goes something like this:
Code for register page
Take value from input boxes
Search my database
If email already exists in my database {
display error
}
else {
register the user
insert a new row of data with email and first name
log the user in
redirect to a page
}
Code for the page user is redirected to
If user is logged in{
search my database
if their data row hasn’t got an id {
update it
}
}