My process is search first if a Member already exists using the email.
If the Member already exists, then its automatically assign it a Role.
If the Member does not exists, then its automatically registers it, then, assign it a Role.
I am having trouble performing a query using the email to check if the Member already exists and get its Member ID.
Below are my codes:
//FRONT-END:
import wixLocation from 'wix-location';
import {myRegisterMemberFunction} from 'backend/autoRegisterMembers.jsw';
import {assignRole} from 'backend/rolesVolunteers.jsw';
import {findEmail} from 'backend/findMemberEmail.jsw';
$w.onReady(function () {
$w('#applyBtn').onClick(function () {
let emailP = $w('#emailAddP').value;
let passwP = $w('#passWordP').value;
let options = {
contactInfo: {
"firstName": $w('#firstNameP').value,
"lastName": $w('#lastNameP').value,
},
"privacyStatus": 'PUBLIC'
}
findEmail(emailP)
.then((results) => {
if(results !== null || results !== undefined) {
let userId = results;
console.log(userId);
assignRole(userId);
}
});
});
});
//BACK-END:
import wixData from 'wix-data';
export function findEmail(email) {
return wixData.query("Members/PrivateMembersData")
.eq("loginEmail",email)
.find()
.then((result) => {
return result.items[0]._id;
})
.catch((error) => {
console.log(error);
});
}
This is the error message in the Logs:
"["Permission denied: {\"message\":\"permission_denied, details: {\\\"RequiredRole\\\":\\\"Member\\\",\\\"GivenIds\\\":\\\"visitor -> a3d80916-f2ae-4981-a8d3-4c1b1a71ce56\\\"}\",\"details\":{\"category\":\"api_error\",\"error\":\"permission_denied\",\"requiredrole\":\"Member\",\"givenids\":\"visitor -> a3d80916-f2ae-4981-a8d3-4c1b1a71ce56\"}}."]"
Its is causing an error in my Back-End code, line 3 on this part: " return wixData.query(“Members/PrivateMembersData”)"