whats the difference between context and middleware

and which 1 should I use for express session cookies
Context is data, middleware is code. Middleware allows you to add reusable code to your procedures - code that runs before and/or after your procedure code. Your context data is typed, and available in all your procedures and their attached middleware. Your context is created on every request, so one way you could handle session cookies is to extract the cookie from the request headers in your createContext function and add the desired session data to your context. Session cookies could be set on the response headers of a login procedure, The docs show examples… https://trpc.io/docs/server/context https://trpc.io/docs/server/middlewares

Looking for more? Join the community!