fix(nuxt): do not accept arbitrary strings for `MiddlewareKey` (#28676)

This commit is contained in:
Thimo Sietsma 2024-08-26 21:57:58 +02:00 committed by Daniel Roe
parent ae8cc86483
commit 0a4113571d
No known key found for this signature in database
GPG Key ID: CBC814C393D93268
2 changed files with 7 additions and 2 deletions

View File

@ -1,16 +1,21 @@
// For pnpm typecheck:docs to generate correct types
import { addPluginTemplate } from 'nuxt/kit'
import { addPluginTemplate, addRouteMiddleware } from 'nuxt/kit'
export default defineNuxtConfig({
typescript: { shim: process.env.DOCS_TYPECHECK === 'true' },
pages: process.env.DOCS_TYPECHECK === 'true',
modules: [
function () {
if (!process.env.DOCS_TYPECHECK) { return }
addPluginTemplate({
filename: 'plugins/my-plugin.mjs',
getContents: () => 'export default defineNuxtPlugin({ name: \'my-plugin\' })',
})
addRouteMiddleware({
name: 'auth',
path: '#build/auth.js',
})
},
],
})

View File

@ -510,7 +510,7 @@ export default defineNuxtModule({
const namedMiddleware = app.middleware.filter(mw => !mw.global)
return [
'import type { NavigationGuard } from \'vue-router\'',
`export type MiddlewareKey = ${namedMiddleware.map(mw => genString(mw.name)).join(' | ') || 'string'}`,
`export type MiddlewareKey = ${namedMiddleware.map(mw => genString(mw.name)).join(' | ') || 'never'}`,
`declare module ${genString(composablesFile)} {`,
' interface PageMeta {',
' middleware?: MiddlewareKey | NavigationGuard | Array<MiddlewareKey | NavigationGuard>',