T
TanStack8mo ago
considerable-lavender

Access cookies in loader/serverFn/client

I'm having a hard time trying to use the cookies in tanstack start. https://stackblitz.com/edit/tanstack-router-z2md6zd1?file=app%2Fcookie-loader.ts In __root.tsx loader is a function to initialize the cookie with a value. I then have 3 different ways to load the cookie: * Directly in the loader * Loader calling a server fn * Client calling a server fn None of those approaches work, they all fail with "Context is not available".
3 Replies
other-emerald
other-emerald8mo ago
Make sure you update to latest version, there were some issues where cookies were not available on first request.
considerable-lavender
considerable-lavenderOP8mo ago
Yes I noticed lots of activity around this the last couple of days, but I have basically tried every single release since 1.97.15. It still fails on latest (1.98.0) By the way. There's also some generic type arguments that are missing on all the wrapped h3 functions in the @tanstack/start/server package. For instance, I cannot do useSession<{data: number}>(sessionConfig). It is happening because tanstack are rewriting the response type of the wrapped function to make the first H3Event optional. I tried to make a fix for it, but haven't found a solution yet, which preserves generic type arguments and makes the H3Event argument optional.
rival-black
rival-black8mo ago
also having issues with cookies, worked on 1.92.11 but doesnt work on latest, and changing import from winxi/http to tanstack/start/server didnt help

Did you find this page helpful?