Backend Javascript runs Fine.. but returns Undefined to Front end

Having an issue I can’t figure out. I’m sure I’m just doing something stupid.

On the front end I’m making a call to backend javascript. I’ve done something similar in other places, but this time around, immediately before I make the call, I can print it to the console and it’s fine. But when I return this exact same value to the front end, then try to print it… it’s returned as ‘undefined’.

Have wondered if I’m using promises wrong, or if I can only return json to the front end, added timestamps to see if it was executing out of order or something…but nothing is working. Idk, I’m stuck. Help is much appreciated.

Here’s a simplified example of the code that has been tested and is still having the issue:

Front end javascript:

checkLoginTest($w(‘#UsernameField’).value, $w(‘#PasswordField’).value, $w(‘#checkbox1’).checked)
.then((httpLoginResponse) => {
const today = new Date();
console.log('onReady Login, timestamp: '+ today.getTime()+ " httpLoginResponse: "+httpLoginResponse);
}

Backend (in loginModule.jsw):
import { fetch } from ‘wix-fetch’;
export function checkLoginTest(username, password, remember_me) {
var bodydata = JSON.stringify({
“user_email”: username,
“password”: password,
“remember_me”: remember_me
});
console.log(‘in backend httpresponse in checkLogin’);
return fetch(“https://server.frink.global/censored”, {
method: “post”,
body: bodydata,
cache: ‘no-cache’,
headers: {
‘Content-Type’: ‘application/json’,
‘Accept’: ‘application/json’,
“cookie”: “”,
},
credentials: ‘include’
})
.then((httpResponse) => {
var today = new Date();
console.log('in backend httpresponse 200 is: Timestamp: '+ today.getTime());
console.log(httpResponse);
if (httpResponse.ok) {
today = new Date();
console.log(“backend return from checkLogin at Timestamp: “+ today.getTime()+” httpResponse.json():”+httpResponse.json());

return httpResponse.json();
}

//return JSON.stringify(response);
})
. catch ((err) => {
console.log(‘Error occured’+err);
return err;
});
}

And finally the error messages I’m getting:
onReady Login, timestamp: 1560143201469 httpLoginResponse: undefined

in backend httpresponse in checkLogin
in backend httpresponse 200 is: Timestamp: 1560143201385

(Interesting front end console output appears before backend even though executed after? Kinda makes sense though)

Thank you very much!!!

Anyone have any thoughts on how to fix this? Thanks.

You might have done this already, however please check Wix pages about using Fetch.
https://support.wix.com/en/article/corvid-accessing-third-party-services-with-the-fetch-api
https://www.wix.com/corvid/reference/wix-fetch.html