Jimmy
How to pass context to vanilla client?
I just found this https://trpc.io/docs/client/links/httpBatchLink#httpbatchlink-options
27 replies
How to pass context to vanilla client?
I think you could write a middleware after the trpc adapter, if the res.headers include Set-Cookie it parses the header and saves the cookie somewhere(could be stored at the top level variable I think), and you also need to write another middleware before the trpc adapter, it writes the cookie to the req.headers if the cookie is not null.
27 replies
How to pass context to vanilla client?
If the node server sets
Set-Cookie
, the browser will automatically add the cookie to the req header on each http calls. I think your question is that your trpc client can't access the req header or the http-only cookies. So my suggestion is that handle the auth event(like validate cookies) through the node middleware, and set something you want to the ctx(like req.trpc.session or ctx.trpc.session), then pass them to trpc context. Make sure the trpc middleware should run after the auth middleware.27 replies