Regarding console : it allows you to debug your code by printing messages, available in preview and browser’s consoles, just like you showed.
So in your case we want to know why a record is created with empty email. So I would add the following lines:
.then((email) => {
// check if there is an item for the user in the collection
console.log("Email retrieved : " + email);
userEmail = email;
and
const toInsert = { "_id": userId, "email": userEmail };
console.log("toInsert :" + toInsert);
Execute in preview mode and tell us the result.