Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
itelo committed Oct 6, 2023
1 parent 0909294 commit d3aac94
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
53 changes: 27 additions & 26 deletions packages/nextlove/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,32 +119,33 @@ export type RouteFunction<SP extends SetupParams, RS extends RouteSpec> = (
any
>
? Omit<NextApiRequest, "query" | "body"> &
AuthMWOut &
MiddlewareChainOutput<
SP["globalAfterAuthMiddlewares"] extends readonly Middleware<any, any>[]
? SP["globalAfterAuthMiddlewares"]
: []
> &
MiddlewareChainOutput<
RS["middlewares"] extends readonly Middleware<any, any>[]
? [...SP["globalMiddlewares"], ...RS["middlewares"]]
: SP["globalMiddlewares"]
> & {
body: RS["formData"] extends z.ZodTypeAny
? z.infer<RS["formData"]>
: RS["jsonBody"] extends z.ZodTypeAny
? z.infer<RS["jsonBody"]>
: {}
query: RS["queryParams"] extends z.ZodTypeAny
? z.infer<RS["queryParams"]>
: {}
commonParams: RS["commonParams"] extends z.ZodTypeAny
? z.infer<RS["commonParams"]>
: {}
}
:

`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<any, any>[]
? [...SP["globalMiddlewares"], ...RS["middlewares"]]
: SP["globalMiddlewares"]
> & {
body: RS["formData"] extends z.ZodTypeAny
? z.infer<RS["formData"]>
: RS["jsonBody"] extends z.ZodTypeAny
? z.infer<RS["jsonBody"]>
: {}
query: RS["queryParams"] extends z.ZodTypeAny
? z.infer<RS["queryParams"]>
: {}
commonParams: RS["commonParams"] extends z.ZodTypeAny
? z.infer<RS["commonParams"]>
: {}
}
: `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
Expand Down

0 comments on commit d3aac94

Please sign in to comment.