@exobase/use-json-args
v1.0.0-rc.3
Published
Exobase hook to parse and validate json body arguments
Downloads
3
Readme
Provides a hook to parse and validate request arguments from the json body.
Install
Yarn
yarn add @exobase/use-json-args
Usage
If you're writing Exobase endpoints in Typescript you'll want to import the Props
type.
import { compose } from 'radash'
import type { Props } from '@exobase/core'
import { useJsonArgs } from '@exobase/use-json-args'
import { useLambda } from '@exobase/use-lambda'
type Args = {
username: string
password: string
}
const createAccount = async ({ args }: Props) => {
// await db.users.add({
// username: args.username,
// password: args.password
// })
}
const STRONG =
/^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$/
export default compose(
useLambda(),
useJsonArgs(yup => ({
username: yup.string().required(),
password: yup
.string()
.matches(STRONG, { message: 'Password is too weak' })
.required()
})),
createAccount
)