Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using axios with axios-cookiejar-support and http-cookie-agent/http #1158

Open
Yehiel-shamir opened this issue Jan 12, 2025 · 0 comments
Open

Comments

@Yehiel-shamir
Copy link

I think I have a similar issue to this, but the solution above did not work for me

so here is my code:

private initializeSession(): AxiosInstance {
    const jar = new CookieJar();
    const session = wrapper(
      axios.create({
        // jar,
        baseURL: this.config.baseUrl,
        xsrfCookieName: 'XSRF-TOKEN',
        xsrfHeaderName: 'X-XSRF-TOKEN',
        httpAgent: new HttpCookieAgent({ keepAlive: true, cookies: { jar } }),
        httpsAgent: new HttpsCookieAgent({ keepAlive: true, cookies: { jar }, rejectUnauthorized: false }),
        // withCredentials: true,
        headers: {
          'Accept': 'application/json', 'Content-Type': 'application/json',
        },
      }),
    );

and in my code I'm trying to get access to my baseUrl cookies
const cookies = await axiosInstance.defaults.jar?.getCookies(${this.config.baseUrl});

now, when I had the Jar as a direct child of the axios object, (e.g. axios.create({jar, ...}) everything work as expected,
but since I tried to use thehttpsAgent: new HttpsCookieAgent({ keepAlive: true, cookies: { jar }, rejectUnauthorized: false }), I get undefined

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

No branches or pull requests

1 participant