mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-16 02:44:51 +00:00
13 lines
311 B
TypeScript
13 lines
311 B
TypeScript
|
import { createError, defineNuxtRouteMiddleware } from '#app'
|
||
|
|
||
|
export default defineNuxtRouteMiddleware(async (to) => {
|
||
|
if (!to.meta?.validate) { return }
|
||
|
|
||
|
const result = await Promise.resolve(to.meta.validate(to))
|
||
|
if (typeof result === 'boolean') {
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
return createError(result)
|
||
|
})
|