Hey, so i’m in desperate need of some assistance. I’m attempting to migrate an existing frontend site into wix. To give you a brief overview of the structure basically there is an API running on a hosted server connected to a database. The public frontend site allows users to login and retrieve personalized information from the database. This is all working fine and this structure cant be changed.
The previous developer used JSONP and ignored all the fun CORS issues. Because i’m trying to do this in wix, i have had to use the Fetch API and its not been going too well. I was hoping someone could have a look at the code i’m using for my calls and point me in the right direction.
Currently the authentication call works perfectly, a token is returned and all is good. The issue i have is it refuses to send it with the next request. All tests with postmaster and even direct browser calls work fine.
/**
-
Authentication call, sends username and password to backend and returns a token
*/
function authenticate(login, password) {
return fetch($apiurl + “login?username=” + login + “&password=” + password, {
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json; charset=utf-8’,
‘Accept’: ‘application/json’,
},
credentials: ‘include’,
mode: ‘cors’}).then( function (response) {
return response.json();
})
}
/**
- Sends token and returns personalized user data.
*/
function getUserDetails() {
return fetch($apiurl + “userdetails”, {
headers: {
‘Content-Type’: ‘application/json; charset=utf-8’,
‘Accept’: ‘application/json’,
},
credentials: ‘include’,
mode: ‘cors’
}).then( function (response) {
return response.json();
})
}
Thanks in advance for any insight you can give me. I’m honestly at my wits end with this one.