verifying length for insert

I am verifying member user input to allow insert. This works for === 0

I would like for it to work for === 1, but it does not work by just making that change, so not sure why not.

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

$w.onReady( () => {
if (wixUsers.currentUser.loggedIn) {
$w(“#button7”).label = “Logout”;
$w(“#button9”).show();
}
else {
$w(“#button7”).label = “Login”;
$w(“#button9”).hide();
}
} );

export function button7_onclick() {
// user is logged in
if (wixUsers.currentUser.loggedIn) {
// log the user out
wixUsers.logout()
.then( () => {
// update buttons accordingly
$w(“#button7”).label = “Login”;
$w(“#button9”).hide();
} );
}
// user is logged out
else {
let userId;
let userEmail;

// 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(“Profile”)
.eq(“_id”, userId)
.find();
} )
.then( (results) => {
// if an item for the user is not found
if (results.items.length === 1) { // this is the line that works with 0, but not 1
// create an item
const toInsert = {
“_id”: userId,
“email”: userEmail
};
// add the item to the collection
wixData.insert(“Profile”, toInsert)
. catch ( (err) => {
console.log(err);
} );
}
// update buttons accordingly
$w(“#button7”).label = “Logout”;
$w(“#button9”).show();
} )
. catch ( (err) => {
console.log(err);
} );
}
}

Maybe the result is never 1. Did you try checking > 0 ?

Use console.log(results.items.length) to see what you’re getting.

0 does not work…only thing that will work is === 0
not sure how to implement the console.log

It may just be my site, a lot of weird things happening lately where permissions changed on pages from what I had and code symbols changed. Really getting paranoid at times that someone is messing with my site as things will be working perfectly and then suddenly not work at all.

This code below was working perfectly for my needs, but suddenly quit working. I’ve gone thru it and checked and rechecked all settings and the code itself, but not finding where any changes occurred on it.