Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Unable to use setCookie() method from the native http plugin for capacitor #88

Closed
kasuvy opened this issue Jan 29, 2021 · 2 comments
Closed

Comments

@kasuvy
Copy link

kasuvy commented Jan 29, 2021

Describe the bug
A clear and concise description of what the bug is.
The project is a Angular/Ionic based. It had the issue with the native IOS not retaining the cookies after authentication to do any subsequent requests. I tried to install the @capacitor-community/http plugin and use the Http to make requests instead of "httpClient" imported from angular. The setCookie() method is not setting the Auth cookie before performing a get/post request.

The below is the screenshot of the Request headers using the angular httpClient (It is having the cookie included in the request header)
Cookie1

The below is the screenshot of the Request headers using the native http plugin (It is missing the cookie in the request header)
Cookie2

CODE SNIPPET:

async get(path, method): Promise<Observable> {
const { Http } = Plugins;
try {
const { Http } = Plugins;
const cookies = await Http.getCookies({
url: this.apiUrl("/cookie"),
});
console.log(cookies);
let retValue = "";
for (let i = 0; i < cookies.value.length; i++) {
retValue = cookies.value[0].value;
}
await Http.setCookie({
url: "http://localhost:8102/",
key: ".ASPXAUTH",
value: retValue,
});
const ret = await Http.request({
method: method,
url: this.apiUrl(path),
headers: {
"X-Fake-Header": "Max was here",
"Content-Type": "application/json",
withCredentials: true,
},
});
console.log("Got ret", ret);
return ret;
} catch (e) {
console.error(e);
}
}

@NKZ15
Copy link

NKZ15 commented Jan 29, 2021

I have the same issue @mlynch @IT-MikeS @thomasvidas. setCookie is not working for me as well. Has there been any updates or any other workarounds for the iOS issue? My iOS app doesn't set cookies the first time it opens.

@thomasvidas
Copy link
Contributor

Duplicate of #47, closing in favor of that. This is a known bug. See #47 and Capacitor Issue #1373 for more details.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants