Replies: 2 comments
-
you can check this discussion with a concrete solution i have given : |
Beta Was this translation helpful? Give feedback.
-
It's a difficult issue as it's kind of case specific with Zodios, so writing a more or less implementation-agnostic MW becomes a challenge. I'd prefer being able to simply use express' Request and Response, but that's not entirely possible. I'd say that the clearest and cleanest solution is to use generics, and typing only what you need. const someCookieHandlingMiddleware = async <T>(req: T & { cookies?: Record<string, string> }, res: unknown, next: express.NextFunction) => {
console.log(req.cookies)
next()
} By doing this, middlewares are not limited to use with Zodios, they can still be used with vanilla Express. This could become complex in very advanced cases, but usually you only need a few props from the req and res object. I'd assume that for auth, you can type the req somewhat like this |
Beta Was this translation helpful? Give feedback.
-
What is the recommended way of typing server middleware? I'm interested in using middleware for authentication, I'm considering just using basic express request and response types for now.
Beta Was this translation helpful? Give feedback.
All reactions