Browser does not recognize the nested variable, but preview mode does.

So I can write this promise and the then() a couple of different ways and the browser won’t recognize the ‘userId’ variable as a search parameter in the .eq of the “AllowedMembers” query. I can place a string there, works just fine. It should work, especially when the promises are nested the second way. It works in the preview mode. Any thoughts why it doesnt work once published.

$w.onReady(function () {

    .then((member) => { 
        userId = member.loginEmail; 
        $w("#greeting").value = userId; 
        $w("#testInput2").value = userId; 

    .then(() => { 
            .eq("title", userId) 
            .then((results) => { 
                //if(results.items.length > 0) { 
                currentID = results.items[0].title; 
                $w('#testInput').value = currentID; 
                //else { 
                // currentID="hello"; 
                // $w('#testInput').value=currentID; 
                // } 
            .catch((error) => { 

    .catch((error) => { 

$w("#logout").onClick((logout) => { 
Here is pic line 22 is problem: doesnt recognize the `userId` variable once published

And here is another way of writing it that also works in preview mode but not published:
i have erased the if else functions that I tried out. line 18 problem:

Any suggestions are welcomed

so I ended up using asynchronous function with await. But the above code may have worked just fine. I would have to run it again to test it. Again, worked on preview, not on publish; as it turns out the browser queries were case sensitive, preview is not. Just an easy fix.