-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Thanks for this small little, but handy middleware. Great work 👏
I extended the default request interface to have a strongly typed parameter and thought, maybe this is also useful for others, or maybe it could even be integrated.
import type { NextApiRequest, NextApiResponse } from 'next'
export interface ValidatedApiRequest<Body = any, Query extends NextApiRequest['query'] = NextApiRequest['query']> extends NextApiRequest {
body: Body
query: Query
}
const query = Joi.object({
id: Joi.string().required(),
});
async function handler(
req: ValidatedApiRequest<undefined, {id: string}>,
res: NextApiResponse
) {
//...
}
export default validator({query}, handler;
Metadata
Metadata
Assignees
Labels
No labels