next-learn icon indicating copy to clipboard operation
next-learn copied to clipboard

Improving accessibility chapter changes validated fields to safeParse() but doesn't mention parsing them out

Open sudiptachatterjee opened this issue 1 year ago • 0 comments

I'm on chapter 14 of the NextJS tutorial and midway through the page, it mentions changing the Zod parse() function to safeParse(). The code sample shows the line change from

const {customerId, amount, status} = CreateInvoice.parse({

to

const validatedFields = CreateInvoice.safeParse({

However, further down the line these variables are used as is in the amountInCents conversion as well as the SQL statements. This is counteracted in the complete code sample for the createInvoice() function by adding this on lines 17-18:

 // Prepare data for insertion into the database
  const { customerId, amount, status } = validatedFields.data;

This should be explicitly mentioned in the tutorial as well, to restore those variables from the validatedFields const that was just created.

sudiptachatterjee avatar Feb 03 '24 08:02 sudiptachatterjee