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

Add option to include cookies in HTTP request executed from client #1868

Open
ekkeguembel opened this issue Nov 1, 2024 · 0 comments
Open
Labels
Improvement ⚡ Something that improves existing feature. Quick to implement.

Comments

@ekkeguembel
Copy link

Describe the bug
I am trying to get a cookie (from a server with another app) through an "execute on client" HTTP request. The cookie is sent in the response from the server, but not stored by the browser.

Analysis
For the browser to store the cookie, we need credentials: 'include' with the fetch. This is not present

Fix / Proof of concept
When I add the credentials: 'include' to web.js (https://cdn.jsdelivr.net/npm/@typebot.io/[email protected]/dist/web.js) in these two places (lines 4454 ff. and 13092 ff. for me), all works nicely:

try {
        let n = typeof e == "string" ? e : e.url;
        t = await fetch(n, {
            method: typeof e == "string" ? "GET" : e.method,
            mode: "cors",
            credentials: 'include',  // Include cookies with the request
            headers: typeof e != "string" && re(e.body) ? {
                "Content-Type": "application/json"
            } : void 0,
            body: typeof e != "string" && re(e.body) ? JSON.stringify(e.body) : void 0
        });
        let r = await t.json();
        if (!t.ok)
            throw "error"in r ? r.error : r;
        return {
            data: r,
            response: t
        }
    } catch (n) {
        return console.error(n),
        {
            error: n,
            response: t
        }
    }

and

 try {
        let i = await fetch(t, {
            method: n,
            credentials: 'include',  // Include cookies with the request
            body: n !== "GET" && r ? JSON.stringify(r) : void 0,
            headers: o
        })
          , a = i.status
          , s = await i.json();
        return JSON.stringify({
            statusCode: a,
            data: s
        })
    } catch (i) {
        return console.error(i),
        JSON.stringify({
            statusCode: 500,
            data: "An error occured while executing the webhook on the client"
        })
    }
@baptisteArno baptisteArno added the Improvement ⚡ Something that improves existing feature. Quick to implement. label Nov 5, 2024
@github-project-automation github-project-automation bot moved this to Backlog ☁️ in Typebot Nov 5, 2024
@baptisteArno baptisteArno changed the title Need credentials: 'include' with fetch Add option to include cookies in HTTP request executed from client Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement ⚡ Something that improves existing feature. Quick to implement.
Projects
Status: Backlog ☁️
Development

No branches or pull requests

2 participants