The Ktor JS engine is not passing cookies by defau...
# ktor
t
The Ktor JS engine is not passing cookies by default 🤔 In the Fetch API (which Ktor uses under the hood), we can set
credentials
to
include
to make this work. How can I make Ktor do this or pass this config? Any help is appreciated 🙏
h
A (lazy) workaround: overwrite the fetch function in your main entrypoint:
Copy code
window.originalFetch = window.fetch;
window.fetch = function (resource, init) {
    return window.originalFetch(resource, Object.assign({ credentials: 'include' }, init || {}));
};
https://youtrack.jetbrains.com/issue/KTOR-539 https://github.com/hfhbd/ComposeTodo/blob/66163246b1e8c3562d92be3f1ee01707e3d23551/web/src/jsMain/kotlin/app/softwork/composetodo/Main.kt#L12
t
Wow, that did the trick! Thanks for the links. I’m surprised how a standard construct is missing from Ktor and is still in progress even after four years of that issue… 🤔
e
Could you try setting
credentials include
into
nodeOptions
? it also should work
t
@e5l I think I tried doing that yesterday, but It didn’t work. I digged little deep into the mapping code and I found for browser there’s a different logic where these options are not mapped to … only basic props are added in here.
e
yep, I discovered this as well and added more generic option for the next minor release
kodee loving 1
please check the PR, the fix will be available in 3.2.0-eap-* build after merging
t
that’s great! will test and update once merged - thanks 🙂