Is there any way to add a user to multiple databases at the same time?
This does not work, but I would love if it did…
// prompt the user to log in
wixUsers.promptLogin( {“mode”: “login”} )
.then( (user) => {
userId = user.id;
return user.getEmail();
} )
.then( (email) => {
// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“Collection 1”);
return wixData.query(“Collection 2”)
.eq(“_id”, userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
“_id”: userId,
“email”: userEmail
};
// add the item to the collection
wixData.insert(“Collection1”, toInsert);
wixData.insert(“Collection2”, toInsert)
.catch( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#button1”).label = “Logout”;
$w(“#button2”).show();
} )
.catch( (err) => {
console.log(err);
} );
}
}
Thanks in advance.