Skip to content

Is there a way to sanitise request inputs using zod? #1358

Answered by nullndr
SandeepGamot asked this question in Q&A
Discussion options

You must be logged in to vote

You can use the .transform() method with any sanitization function on the schema:

const s = z.object({ email: z.string(), pass: z.string() }).transform(v => {
  return {
    email: sanitize(v.email),
    pass: sanitize(v.pass),
  }
})

Replies: 4 comments 6 replies

Comment options

You must be logged in to vote
5 replies
@Fritze1602
Comment options

@JacobWeisenburger
Comment options

@aravsanj
Comment options

@nullndr
Comment options

@sbeben
Comment options

Answer selected by JacobWeisenburger
Comment options

You must be logged in to vote
1 reply
@nullndr
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
9 participants