fix(kit): clone middleware when adding to app

This commit is contained in:
Daniel Roe 2024-03-15 15:38:07 -07:00
parent 4be430e13f
commit 5be9253cfe
No known key found for this signature in database
GPG Key ID: CBC814C393D93268

View File

@ -53,12 +53,12 @@ export function addRouteMiddleware (input: NuxtMiddleware | NuxtMiddleware[], op
if (find >= 0) { if (find >= 0) {
if (app.middleware[find].path === middleware.path) { continue } if (app.middleware[find].path === middleware.path) { continue }
if (options.override === true) { if (options.override === true) {
app.middleware[find] = middleware app.middleware[find] = { ...middleware }
} else { } else {
logger.warn(`'${middleware.name}' middleware already exists at '${app.middleware[find].path}'. You can set \`override: true\` to replace it.`) logger.warn(`'${middleware.name}' middleware already exists at '${app.middleware[find].path}'. You can set \`override: true\` to replace it.`)
} }
} else { } else {
app.middleware.push(middleware) app.middleware.push({ ...middleware })
} }
} }
}) })