# Return from function

**URL:** <https://forum.wixstudio.com/t/return-from-function/8418>\
**Category:** Ask the community\
**Tags:** wix-members-area, code, question\
**Created:** [January 24, 2022, 8:45pm UTC](https://forum.wixstudio.com/t/return-from-function/8418 "2022-01-24T20:45:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ambenali](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/ambenali/32/122065_2.png) [@ambenali](https://forum.wixstudio.com/u/ambenali)\
**Post date:** [January 24, 2022, 8:45pm UTC](https://forum.wixstudio.com/t/return-from-function/8418/1 "2022-01-24T20:45:19Z")

</div>

Hello,

I am trying to retrieve the active user’s email address, which is then used to find the user’s unique id created for the site (different from the id assigned by Wix).

While this code work in terms of finding the right Id, what it returns is described as “Undefined” when I call the function from onReady.

This is the search code/function:  
export function getUserInfo2 ( activeUserId ) {  
wixData . query ( “Members/PrivateMembersData” )  
. eq ( “\_id” , activeUserId )  
. limit ( 1 )  
. find ()  
. then ( ( results ) =\> {  
activeUserEmail = results . items [0]. loginEmail ;  
wixData . query ( “dbUsers” )  
. eq ( “emailAddress” , activeUserEmail )  
. limit ( 1 )  
. find ()  
. then ( results =\> {  
if ( activeUserEmail === results . items [0]. emailAddress ) {  
userUpId = results . items [0]. upliftId ;  
**return** ( userUpId );  
//$w(“#txtTestLogin”).text = "Hello " + results.items[0].userName;  
}  
})  
});  
}

And this is how I am calling the function in onReady:

( **async** () =\> {  
console . log ( "User Id within the site: " + **await** getUserInfo2 ( activeUser . id ))  
})();

What am I doing wrong?

Thank you in advance.

Amine

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [January 24, 2022, 9:14pm UTC](https://forum.wixstudio.com/t/return-from-function/8418/2 "2022-01-24T21:14:55Z")

</div>

You should not nest promises but chain them.

WRONG:

```javascript
export function x(arg){
    query1.find().then(res => {
        query2.find()
        .then(res => {
            return something;
        })
    })
}

```

RIGHT:

```javascript
export function x(arg){
    return query1.find().then(res => {
        return query2.find();
    })
    .then(res => {
        return something;
    })
 }

```

---

<div class="post-metadata">

**Author:** ![ambenali](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/ambenali/32/122065_2.png) [@ambenali](https://forum.wixstudio.com/u/ambenali)\
**Post date:** [January 24, 2022, 9:40pm UTC](https://forum.wixstudio.com/t/return-from-function/8418/3 "2022-01-24T21:40:01Z")

</div>

Thank you J.D.! That resolved the issue, and I learned something new.  
All the best.
