Cookie lost in Request.postJSON

(I’m using svelte)

Hello, the issue is that i make a postJSON request to make the user login on my backend server with this line of code:
f7.request.postJSON(store.state.baseurl + 'API/Login',{email:email, pass:password}).then(....

The server response has a ASP.NET_SessionId cookie that i have to use on the further requests.

But when I make a new request with this line of code:
f7.request.postJSON(baseurl + 'API/GetRoles').then(....

No cookie is used on that request and because that my backend thinks I’m not logged in.

So, how can I make a request using the cookie provided to me on the first request to the server (login one)?

I think this may be because of CORS, i think that it could be fixed by adding a
credentials: 'include',
to the fetch function but as I’m using framework7 postJSON function I don’t know where to set the hearders of that request.

Okay, I’ve already tried to add the credentials include using request.setup and that does not solve the issue.

I think is a problem with setcookie but i cant realise how to solve it.

Please help @nolimits4web

I am not a cookie pro, but as far as I remember, cookies are not participating directly in requests, you first set cookie on front end with document.cookie = ... and if it was set correctly then browser sends them automatically with every request

Hello @nolimits4web i’ve managed to solve it using this snippet:
beforeSend: function(xhr) {
xhr.withCredentials = true;

Could you tell me how to run this on startup (and in what file)? because when i try to run it on startup most of the times f7 is not ready. (using svelte)

You can import/use request without f7 instance Request | Framework7 Documentation, so basically in any file, preferably in your main file I guess, you can do:

import { request } from 'framework7';

1 Like