A module to easily use VineJS in Nuxt for for server-side validation!
- 📦 Easy Setup: Just add the module to your Nuxt config and you're good to go!
- 🪄 Automatic error handling: Errors are automatically handled when a validation fails.
- Add
nuxt-vine
dependency to your project
# Using pnpm
pnpm add -D nuxt-vine
# Using yarn
yarn add --dev nuxt-vine
# Using npm
npm install --save-dev nuxt-vine
- Add
nuxt-vine
to themodules
section ofnuxt.config.ts
export default defineNuxtConfig({
modules: [
'nuxt-vine'
]
})
That's it! You can now use Nuxt Vine in your Nuxt app ✨
This plugin automatically imports composable functions into your Nitro routes.
export default defineEventHandler(async (event) => {
const { title } = await validateBody(event, {
title: v.string()
})
// If validation failed, an error will be thrown and handled by this package.
return title
})
v
is an alias for vine
.
You can use:
validateBody
to validate the body of a requestvalidateQuery
to validate the query of a requestvalidateParams
to validate the params of a request
# Install dependencies
npm install
# Generate type stubs
npm run dev:prepare
# Develop with the playground
npm run dev
# Build the playground
npm run dev:build
# Run ESLint
npm run lint
# Run Vitest
npm run test
npm run test:watch
# Release new version
npm run release
Thanks Atinux for the initial works!