TanStackT
TanStack7d ago
7 replies
spotty-amber

Is it possible to add "credentials: include" to a createServerFn POST request?

I currently run Tanstack Start with Hono as a persistent server, i have Hono CORS middleware sitting on top.

I am trying to make a createServerFn({ method: "POST" }) request that returns a set-cookie header. Since I am making a POST request that hits my Hono server with CORS i need to be able to add "credentials: include" to the request but I am struggling to find how i can modify the "fetcher" that the createServerFn uses so that I can pass this property?

    const setTheme = useServerFn(setThemeServerFn);

    const router = useRouter();

    const onSetTheme = useCallback(
        (theme: Theme) => {
            setTheme({
                data: theme,
                credentials: "include", // would be nice to be able to do this?
            }).then(() =>

            );
        },
        [router, setTheme],
    );


using Start's setCookie does set the response header in the start.ts server handler, but it gets stripped away currently by the CORS middleware before returning to the client and I think being able to just pass the credentials property would fix this
Was this page helpful?