I am trying to do below things. I want to get the current logged in user and pass the email to fetch url to get the data.

backend code


export function fetchdata() {
 

 return fetch('<API URL>', {method: 'get'})
    .then(response => response.json())

    .then((data) => {
       user.getEmail()
        .then( (email) => {
 
 return data[email];
        })
        .then( (results) => {
 
 return results;
        } );
 
   })
}

client side code

import { fetchdata } from 'backend/fetchTransaction';

$w.onReady( async function () {
 fetchdata()
    .then(items => console.log('-----------'+items));
 
} );

I am not getting the callback correctly in the client side

I fixed it by doing below change:





export function fetchdata() {

 return fetch("<API URL>", { method: 'get' })
        .then((response) => {
 return response.json()
                .then((json) => {
 return user.getEmail()
                        .then((email) => {
 return json[email];
                        });
                });
        });

}