Nitro · correctness

NITRO0030Don't return an assigned value from server middleware

Reports server middleware whose default-exported handler returns the result of an assignment, such as an arrow body `event.context.user = user`, `Object.assign(event.context, ...)`, or `return event.context.x = value`. Only files Nitro scans from middleware/ are checked. Explicit return values, such as createError() or sendRedirect(), are left alone. Unresolved layers, environment overrides, custom scan suffixes, ignore options, and .nuxtignore are evidence gaps.

Why it happens

Nitro runs every middleware before the route handler and treats any value a middleware returns, other than undefined, as the response. An arrow function with an assignment body returns the assigned value, so a middleware that only meant to set event.context ends every request with that value and the route handler never runs.

Fix

For an arrow expression body, use a block body that performs the assignment without returning a value. For a return statement, evaluate the assignment and then use a bare return on the same branch to preserve the early exit.

Example

Use a block body for context assignments

Before

export default defineEventHandler((event) => event.context.user = getUser(event))

After

export default defineEventHandler((event) => {
  event.context.user = getUser(event)
})

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --framework nitro --rules nitro/middleware/no-implicit-response
Copyright © 2026