mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): do not accept arbitrary strings for MiddlewareKey
(#28676)
This commit is contained in:
parent
ae8cc86483
commit
0a4113571d
@ -1,16 +1,21 @@
|
|||||||
// For pnpm typecheck:docs to generate correct types
|
// For pnpm typecheck:docs to generate correct types
|
||||||
|
|
||||||
import { addPluginTemplate } from 'nuxt/kit'
|
import { addPluginTemplate, addRouteMiddleware } from 'nuxt/kit'
|
||||||
|
|
||||||
export default defineNuxtConfig({
|
export default defineNuxtConfig({
|
||||||
typescript: { shim: process.env.DOCS_TYPECHECK === 'true' },
|
typescript: { shim: process.env.DOCS_TYPECHECK === 'true' },
|
||||||
pages: process.env.DOCS_TYPECHECK === 'true',
|
pages: process.env.DOCS_TYPECHECK === 'true',
|
||||||
modules: [
|
modules: [
|
||||||
function () {
|
function () {
|
||||||
|
if (!process.env.DOCS_TYPECHECK) { return }
|
||||||
addPluginTemplate({
|
addPluginTemplate({
|
||||||
filename: 'plugins/my-plugin.mjs',
|
filename: 'plugins/my-plugin.mjs',
|
||||||
getContents: () => 'export default defineNuxtPlugin({ name: \'my-plugin\' })',
|
getContents: () => 'export default defineNuxtPlugin({ name: \'my-plugin\' })',
|
||||||
})
|
})
|
||||||
|
addRouteMiddleware({
|
||||||
|
name: 'auth',
|
||||||
|
path: '#build/auth.js',
|
||||||
|
})
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
@ -510,7 +510,7 @@ export default defineNuxtModule({
|
|||||||
const namedMiddleware = app.middleware.filter(mw => !mw.global)
|
const namedMiddleware = app.middleware.filter(mw => !mw.global)
|
||||||
return [
|
return [
|
||||||
'import type { NavigationGuard } from \'vue-router\'',
|
'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)} {`,
|
`declare module ${genString(composablesFile)} {`,
|
||||||
' interface PageMeta {',
|
' interface PageMeta {',
|
||||||
' middleware?: MiddlewareKey | NavigationGuard | Array<MiddlewareKey | NavigationGuard>',
|
' middleware?: MiddlewareKey | NavigationGuard | Array<MiddlewareKey | NavigationGuard>',
|
||||||
|
Loading…
Reference in New Issue
Block a user