1.0.0-rc.26 • Published 11 months ago

@exobase/use-json-body v1.0.0-rc.26

Weekly downloads
-
License
MIT
Repository
-
Last release
11 months ago

title: 'useJsonBody' description: 'A hook to parse and validate a request body' group: 'Hooks'

badge: 'Validation'

Provides a hook to parse and validate request arguments from the json body.

Install

yarn add @exobase/use-json-body
# or
yarn add @exobase/hooks

Import

import { useJsonBody } from '@exobase/use-json-body'
// or
import { useJsonBody } from '@exobase/hooks'

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 { useJsonBody } from '@exobase/use-json-body'
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 = /^(?=.*[0-9])(?=.*[!@#$%^&*])[a-zA-Z0-9!@#$%^&*]{6,16}$/

export default compose(
  useLambda(),
  useJsonBody(z => ({
    username: z.string(),
    password: z.string().refine(p => STRONG.test(p), {
      message: 'Password is too weak'
    })
  })),
  createAccount
)
1.0.0-rc.26

11 months ago

1.0.0-rc.25

1 year ago

1.0.0-rc.24

1 year ago

1.0.0-rc.20

1 year ago

1.0.0-rc.23

1 year ago

1.0.0-rc.22

1 year ago

1.0.0-rc.21

1 year ago

1.0.0-rc.18

2 years ago

1.0.0-rc.17

2 years ago

1.0.0-rc.16

2 years ago

1.0.0-rc.15

2 years ago

1.0.0-rc.14

2 years ago

1.0.0-rc.13

2 years ago

1.0.0-rc.12

2 years ago

1.0.0-rc.9

2 years ago

1.0.0-rc.7

2 years ago

1.0.0-rc.8

2 years ago

1.0.0-rc.11

2 years ago

1.0.0-rc.10

2 years ago

1.0.0-rc.6

2 years ago

1.0.0-rc.5

3 years ago

1.0.0-rc.4

3 years ago