shmookoff
Explore posts from serversreact-query no cookies on initial load
...and the relevant issue: https://github.com/t3-oss/create-t3-app/issues/1765
6 replies
react-query no cookies on initial load
I suppose the procedure on step 3 is invoked server side using
TRPCReactProvider
. This explains why there are no cookies. Why though? I thought the react-query client should only be used client side.. Should I ask this question to the t3 team?6 replies
TTCTheo's Typesafe Cult
•Created by Rafael Corrêa on 11/9/2023 in #questions
Set cookie within trpc
@Hosenur The docs does not include
cookies
under functions in Pages Router. I suppose, you would need to use some other function.26 replies
TTCTheo's Typesafe Cult
•Created by Rafael Corrêa on 11/9/2023 in #questions
Set cookie within trpc
Thanks. Could you please send from where the error is thrown? The error says that it originates from
auth.register
handler and specifies that cookies was called outside of a request scope. I would like to see the code where cookies
was used.26 replies
TTCTheo's Typesafe Cult
•Created by Rafael Corrêa on 11/9/2023 in #questions
Set cookie within trpc
I'm no expert on pages router, but I think I can look into that. Could you please share the code?
26 replies
TTCTheo's Typesafe Cult
•Created by shmookoff on 2/28/2024 in #questions
How does NextAuth persist session cookie in t3 stack
Even if what I've come to is true, how does it work when a user requests a RSC? By the time
createTRPCContext
is called, the RSC response is already sent, so it won't take any additional cookies that are set by NextAuth.
I'm really confused here.3 replies
TTCTheo's Typesafe Cult
•Created by Rafael Corrêa on 11/9/2023 in #questions
Set cookie within trpc
Awesome! Thanks for letting me know ❤️
26 replies
TTCTheo's Typesafe Cult
•Created by Rafael Corrêa on 11/9/2023 in #questions
Set cookie within trpc
I suppose you can create a separate trpc client with a link that is not streamed, and use it for those operations. That's too much hassle for my taste though.
26 replies
TTCTheo's Typesafe Cult
•Created by Rafael Corrêa on 11/9/2023 in #questions
Set cookie within trpc
Hey, @Rafael Corrêa. I was stuck at this too minutes ago until I experienced the 'Uh' moment.
In t3 by default, react's client is configured with
unstable_httpBatchStreamLink
(the requests are batched and streamed in as they are completed) https://trpc.io/docs/client/links/httpBatchStreamLink.
Because of streaming, the response is already sent by the time a cookie is set. This is why you can't set a cookie in RSC.
Basically, there're two (reasonable) ways:
either give up on streaming and use a different link
or don't use trpc for operations that require setting a cookie.
I'm going with the first way as I don't think streaming will provide much benefit in my case. For that, just replace unstable_httpBatchStreamLink
in react's trpc client with httpBatchLink
https://trpc.io/docs/client/links/httpBatchLink
Let me know if that helps you26 replies