Hello, I’ve managed to register/create multiple members and sending them emails with their password with this code on the frontend:
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import { backendmail } from 'backend/Emails';
export function button1_click(event) {
return wixData.query("UsuariosCSV")
.limit(1000)
.find()
.then((result) => {
let items = result.items;
for (var i = 0; i < items.length; i++) {
if (items[i] === null) continue;
//console.log(i);
let pass = items[i].pass;
let nombre = items[i].nombre;
let email = items[i].email;
wixUsers.register(email, pass);
//console.log('member created');
wixData.query("Members/PrivateMembersData")
.eq("loginEmail", email)
.find()
.then((results) => {
let idResults = []
results.items.forEach(function (element) {
idResults.push(element._id);
})
//console.log(idResults[0]);
//console.log(pass);
//console.log(nombre);
backendmail(idResults[0], pass, nombre);
});
}
});
}
And this little module on the backend:
import wixUsersBackend from 'wix-users-backend';
export function backendmail(user_id,pass,name) {
return wixUsersBackend.emailUser('TestPass', user_id, {
variables: {
passw: pass,
Nombrew: name
}
})
.then(() => {
console.log("email sent")
})
.catch((err) => {
console.log("not sent")
})
}
But I’m receiving this error: “Cannot read property ‘member’ of null”. And is not sending 1 of the emails on the list; can anyone help me spot the issue?