We are not able to set-cookie

We are using Ionic capacitor framework and the problem. we can’t seem to access or see the set-cookie of the header. But i can see it in the Browsers Network Tab. We have also added and http Interceptor with the following code
request = request.clone({
withCredentials: true
});
Still we are having issues. Any help would be great!

What are you trying to use cookies for? From my knowledge, it isn’t really recommended to rely on cookies in a Ionic/Capacitor app.

We have a 3rd party integration for authentication and that requires to respect the cookies that is to be sent by the application .

Thank you for reply.

I am with the same problem now, I need to access the cookies to be able to login against my server.
What is recommended to do?

I think you might now be able to use the Capacitor Cookie plugin. My guess is that you would also need to use the HTTP plugin as well which intercepts JS calls and sends them through native HTTP requests.

The release notes of Capacitor 4.6.0 say:

  • cookies: Use Set-Cookie headers to persist cookies (57f8b39)

so assuming sending a Set-Cookie from your server, Capacitor will set the cookie in native land.

2 Likes

I am facing the same problem;
I have tried Angular HttpClient and Capacitor HTTP client;
I have a backend which set cookie to store some informations, it works fine in the web app, and we have decided to move it to ionic.
but when trying to set-Cookie something goes wrong,
I have enabled CapacitorCookies and CapacitorHttp inside capacitor.config.ts
when I make request either by angular or capacitor clients cookies response fine as

Set-Cookie session=CfDJ8BPwIyS…; path=/; secure; samesite=lax; httponly

However it seems that the ionic app can’t see it but it is shown in Browsers Network Tab
That behavior is the same in browser and android emulator.

Here is example of network tab of angular application without ionic (which work totally fine)
image

and here is example of the ionic app with angular

image