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:
function ControlloEmail () {
return wixData.query("Members/PrivateMembersData")
.eq('loginEmail', $w("#InputMail").value)
.find()
.then( (results) => {
if (results.totalCount > 0) {
emailStato = false;
console.log('utente esistente')
} else {
emailStato = true;
console.log('nessun Utente')
}
return
});
}
In Preview everything works, but in Live it doesn't work and it gives me an error inspecting the console. This is ScreenShot Error
![](https://static.wixstatic.com/media/a27d24_46e0de66bbf143a199b00193440ef434~mv2.jpg/v1/fill/w_980,h_852,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/a27d24_46e0de66bbf143a199b00193440ef434~mv2.jpg)
Someone knows if there are problems in the code for querying the member collection
Thank you
Hi RedDany,
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
}
}
I leave an update.
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.
This is correct, someone can help me
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
Someone from the wix team who can help me
I also read your post Shiro,
https://www.wix.com/corvid/forum/community-discussion/custom-signup-form-error-catching
and tried to remove the returns from the promises like you did:
FormRegister.jsw file in back-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
I don't know what to do or if it's a BUG
I did tests.
I moved the query to the back end, but as before it works in preview and in live does not work giving me the same error
I write the code below:
FormRegister.jsw file in back-end
import wixData from 'wix-data'; export function ControlloEmail(Email) { return 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 () { return ControlloEmail ($w("#InputMail").value) .then( (Stato) => { console.log('Stato da BackEnd - ' + Stato) }); } }
I used this post to create the code
https://support.wix.com/en/article/corvid-security-considerations#code-visibility
Someone who finds the same problem ?
Hi Shiro,
I'm actually working in front-end. I try to go into BackEnd following your suggestion and then give feedback on it.
Yes I had seen qeul post, but front-end or back-end was not specified
Thank you
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.
I've found this post which might help you:
https://www.wix.com/corvid/forum/community-discussion/how-to-query-the-privatemembersdata-collection