From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Shipping address Zod schema and page

Shipping address Zod schema and page

OK, so now we want to work on the shipping address page. So if we go to proceed to checkout from the cart, it goes to slash shipping address. Now, before we create the actual page, I want to create the Zod schema for validation and also the type, the TypeScript type, which we can infer from the Zod schema. So let's go to lib validators. And let's add a schema for the shipping address. So export, const, and we're going to call this shipping address schema, and set that equal to a z.object, and then pass in our fields. So first one is going to be full name, and that's going to be a string, so z.string. And then let's add a min, and I'm just going to set all these to three characters minimum. If you want to change that, you can. So I'll just say name must be at least three characters. And then I'm just going to copy that line down a few times. All right, now the second one is going to be the street address, so street address. And I'm just going to keep it at three. I mean, it should…

Contents