You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const body =awaituseSafeValidatedBody(event, LoginSchema);
52
+
53
+
if (!body.success) // do something
54
+
55
+
returnbody.output;
56
+
}),
57
+
);
58
+
```
59
+
60
+
## Utils available
61
+
62
+
`h3-valibot` provides a series of utils, that each also comes in the `useSafeValidated*` variant for safe validation (doesn't throw an error):
63
+
64
+
-`useValidatedBody`
65
+
-`useValidatedParams`
66
+
-`useValidatedQuery`
67
+
68
+
Each one accepts an h3 `event`, a valibot `schema` and optionally a parser `config`.
69
+
70
+
### Helpers
71
+
72
+
It also provides a set of helpers via `vh` object, mainly related to string validation, particularly useful during the prototyping phase of any project. For production use we still suggest to create dedicated schemas with project-related error messages and fallbacks.
73
+
74
+
-`boolAsString`
75
+
-`checkboxAsString`
76
+
-`intAsString`
77
+
-`numAsString`
78
+
-`uuid`
79
+
80
+
For more details or examples please refer to their JSdocs or [source code](/src/core/schemas.ts).
81
+
45
82
## Errors
46
83
47
-
h3-valibot throws an `ValiError` when the validation fails:
84
+
`h3-valibot` throws an `ValiError` when the validation fails:
0 commit comments