{"repo":"rexfordessilfie/nextwrappers","free":true,"listed":false,"github":"https://github.com/rexfordessilfie/nextwrappers","clone":"git clone https://github.com/rexfordessilfie/nextwrappers.git","description":"Reusable, composable middleware-like wrappers for Next.js App Router Route Handlers and Middleware.","language":"TypeScript","stars":30,"topics":["middleware","next","nextjs"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"nextwrappers Reusable, composable middleware-like wrappers for Next.js API route and middleware.ts handlers. Get Started 🚀 1. First install the core library using your favorite package manager: OR Install and use pre-made (utility) wrappers in the packages directory: 2. Next, create a route handler wrapper function with wrapper , as follows: App Router Pages Router 3. Finally, wrap the wrapper around an Next.js API handler in a pages/api file: App Router Pages Router NB: We are using createApiHandler method to create a handler which we can selectively apply wrappers for different request methods, and then we register a GET handler for the GET method. Features ✨ Here are some of the utility methods provided by the core library. wrapper() , wrapperM() Creates a wrapper around a route/middleware handler that performs some arbitrary piece of logic. It gives you access to the route handler's request , an ext object containing path parameters, and a next function for executing the wrapped route handler. Example - authenticated() Ensure a user has been authenticated with next-auth before continuing with request, then attach current user to the request. Example - restrictedTo() We can also create wrappers with arguments, such as this one to ensure a user has the right role to access the API route. NB: InferReq is a utility type that lets us infer the request type of a wrapper. This is useful when we want to combine multiple wrappers that share the same request type. stack() , stackM","default_branch":null,"files":null,"tree":[],"storefront":"/r/rexfordessilfie","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/rexfordessilfie/nextwrappers/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}