Jimmy
Jimmy
TtRPC
Created by Tuxer on 5/14/2023 in #❓-help
How to pass context to vanilla client?
To rewrite the fetch() function
27 replies
TtRPC
Created by Tuxer on 5/14/2023 in #❓-help
How to pass context to vanilla client?
I think this is the best way now. 😫
27 replies
TtRPC
Created by Tuxer on 5/14/2023 in #❓-help
How to pass context to vanilla client?
27 replies
TtRPC
Created by Tuxer on 5/14/2023 in #❓-help
How to pass context to vanilla client?
Hmmm, the middleware I said is the server side not the trpc's.
27 replies
TtRPC
Created by Tuxer on 5/14/2023 in #❓-help
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
TtRPC
Created by Tuxer on 5/14/2023 in #❓-help
How to pass context to vanilla client?
Since the Node.js will not handle the Set-Cookie automatically, you should parse the header and save the token manually in the server adapter.
27 replies
TtRPC
Created by Tuxer on 5/14/2023 in #❓-help
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