diff --git a/apps/example-todo-app/lib/middlewares/with-global-middeware-after-auth.ts b/apps/example-todo-app/lib/middlewares/with-global-middeware-after-auth.ts index 774800a31..c16184d0d 100644 --- a/apps/example-todo-app/lib/middlewares/with-global-middeware-after-auth.ts +++ b/apps/example-todo-app/lib/middlewares/with-global-middeware-after-auth.ts @@ -1,18 +1,21 @@ import { Middleware } from "nextlove" -export const withGlobalMiddlewareAfterAuth: Middleware<{ - auth: { - authorized_by: "auth_token" - seam: "withGlobalMiddlewareAfterAuth" +export const withGlobalMiddlewareAfterAuth: Middleware< + { + auth: { + authorized_by: "auth_token" + seam: "withGlobalMiddlewareAfterAuth" + } + }, + { + auth: { + authorized_by: "auth_token" + } } -}, { - auth: { - authorized_by: "auth_token" - } -}> = (next) => async (req, res) => { +> = (next) => async (req, res) => { req.auth = { ...req.auth, - seam: "withGlobalMiddlewareAfterAuth" + seam: "withGlobalMiddlewareAfterAuth", } return next(req, res) diff --git a/packages/nextlove/src/types/index.ts b/packages/nextlove/src/types/index.ts index 35a88821f..dc5802bb8 100644 --- a/packages/nextlove/src/types/index.ts +++ b/packages/nextlove/src/types/index.ts @@ -119,32 +119,33 @@ export type RouteFunction = ( any > ? Omit & - AuthMWOut & - MiddlewareChainOutput< - SP["globalAfterAuthMiddlewares"] extends readonly Middleware[] - ? SP["globalAfterAuthMiddlewares"] - : [] - > & - MiddlewareChainOutput< - RS["middlewares"] extends readonly Middleware[] - ? [...SP["globalMiddlewares"], ...RS["middlewares"]] - : SP["globalMiddlewares"] - > & { - body: RS["formData"] extends z.ZodTypeAny - ? z.infer - : RS["jsonBody"] extends z.ZodTypeAny - ? z.infer - : {} - query: RS["queryParams"] extends z.ZodTypeAny - ? z.infer - : {} - commonParams: RS["commonParams"] extends z.ZodTypeAny - ? z.infer - : {} - } - : - - `unknown auth type: ${RS["auth"]}. You should configure this auth type in your auth_middlewares w/ createWithRouteSpec, or maybe you need to add "as const" to your route spec definition.`, + AuthMWOut & + MiddlewareChainOutput< + SP["globalAfterAuthMiddlewares"] extends readonly Middleware< + any, + any + >[] + ? SP["globalAfterAuthMiddlewares"] + : [] + > & + MiddlewareChainOutput< + RS["middlewares"] extends readonly Middleware[] + ? [...SP["globalMiddlewares"], ...RS["middlewares"]] + : SP["globalMiddlewares"] + > & { + body: RS["formData"] extends z.ZodTypeAny + ? z.infer + : RS["jsonBody"] extends z.ZodTypeAny + ? z.infer + : {} + query: RS["queryParams"] extends z.ZodTypeAny + ? z.infer + : {} + commonParams: RS["commonParams"] extends z.ZodTypeAny + ? z.infer + : {} + } + : `unknown auth type: ${RS["auth"]}. You should configure this auth type in your auth_middlewares w/ createWithRouteSpec, or maybe you need to add "as const" to your route spec definition.`, res: NextApiResponseWithoutJsonAndStatusMethods & SuccessfulNextApiResponseMethods< RS["jsonResponse"] extends z.ZodTypeAny